I am new to C#. I have a class with some methods in it, who use the solver object. But, for each of the method i need to again create an instance of solver object to use it. Can some one tell me how to avoid doing this by using interfaces? Making an interface is not a problem, but how to use it once it has been made??
Eg: This is my interface, that contains a solver
public interface ISolver
{
public void Solve(Solver s);
}
This is a method that implements ISolver interface
public void Solve(Solver s)
{
Context ctx = new Context();
ctx.MkSolver();
}
I want to use this inside some methods(note: I have only one single class that contains different methods) One of the method is as follows:
public void MyCheck(Expression expr)
{
BoolExpr boolVal = dispatch(expr);
Solver s = ctx.MkSolver();
Console.WriteLine(boolVal);
s.Assert(boolVal);
Console.WriteLine("\n ");
Console.WriteLine(s.Check());
Console.WriteLine(ReturnTrueFalse(s));
Console.WriteLine("\n ");
}
and the other is:
public bool isContradiction(Expression expr)
{
BoolExpr boolVal = dispatch(expr);
Solver s = ctx.MkSolver();
s.Assert(boolVal);
Status result = s.Check();
return result == Status.UNSATISFIABLE;
}
How to stop using Solver s = ctx.MkSolver(); in each and every method by using this interface. Any help would be appreciated. Thanks.