Implementing the Framework
That is all that is required for the application framework builder to do, the
end user performs the next step to inherit the framework base class and override
all the abstract class defined the framework base class to provide customized
functionality.
// class derived from the base class
class MyClass : AppFramework
{
// methods providing customized implementation for the abstract methods
override public void init()
{
Console.WriteLine("MyClass::init");
}
override public void run()
{
Console.WriteLine("MyClass::run");
}
override public void destroy()
{
Console.WriteLine("MyClass::destroy");
}
// the main method defined
public static void Main(String [] arg)
{
MyClass myClass = new MyClass();
}
}
Although it is not necessary for the Main method to be included in the same
class which overrides the framework methods; it could well be in a separate
class. The complete code listing is as follows.
using System;
abstract class AppFramework
{
public AppFramework()
{
templateMethod();
}
public abstract void init();
public abstract void run();
public abstract void destroy();
private void templateMethod()
{
Console.WriteLine("Initializing Template Engine");
init();
run();
destroy();
Console.WriteLine("Ending Template Engine");
}
}
class MyClass : AppFramework
{
override public void init()
{
Console.WriteLine("MyClass::init");
}
override public void run()
{
Console.WriteLine("MyClass::run");
}
override public void destroy()
{
Console.WriteLine("MyClass::destroy");
}
public static void Main(String [] arg)
{
MyClass myClass = new MyClass();
}
}