Building Application Framework with C#

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();
  }
}

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programs must be written for people to read, and only incidentally for machines to execute.”