Make methods work independently without using a common method
I am currently trying to separate out the method implementation so that
they can work independently. The methods that I am trying to separate are
store and checker. Both these methods require the traverse method. My
current implementation has two method store and checker methods which I
have separated them into different classes. They require to be called
within the traverse method to work. This is the my current implementation.
class Traverse
{
public void traversemethod()
{
Console.WriteLine("Traverse function");
Checker r = new Checker();
r.checkermethod();
Store s = new Store();
s.storemethod();
}
}
class Checker
{
public void checkermethod()
{
Console.WriteLine("Checker function");
}
}
class Store
{
public void storemethod()
{
Console.WriteLine("Store function");
}
}
class Compute
{
public static void Main()
{
Console.WriteLine("Main function");
Traverse v = new Traverse();
v.traversemethod();
Console.ReadLine();
}
Is there any way by which I can implement them separately without
declaring them together in traverse method and calling both store and
checker method separately in the main function. I can implement the
traverse method in both store and checker method, but i was wondering if
there is any way to do it rather than duplicating the same code again.
No comments:
Post a Comment