Building Application Framework with C#

Page 2 of 3
  1. Introduction
  2. Application Framework using C#
  3. Implementing the Framework

Application Framework using C#

In the following article, you'll see how to implement a basic infrastructure for Application Framework Model. The fundamental concept in building application framework is the template method, which is hidden inside the application and controls the flow of the application. This method is characteristically implemented in the base class and cannot be changed.

The first step is to construct the base class for the framework. The base class is the most important class when building application framework. It consists of override able method, which the end user should override to provide customized application. Apart from these, there is also a template method that as mentioned controls the framework processing.

The framework that we are going to built consist of three abstract methods for the end user to implement. These are init, run and destroy which must be implemented in sequence.So the base class for that kind of framework can be implemented as following.

// The class is defined abstract because the customized methods have no definitions
  abstract class AppFramework
  {
  // the constructor which calls the template methods
  public AppFramework()
  {
  templateMethod();
  }

// the method required to be implemented by the end user

public abstract void init();
  public abstract void run();
  public abstract void destroy();

// the template method which is the heart of the framework
  private void templateMethod()
  {
  Console.WriteLine("Initializing Template Engine");
  // template method calling the necessary function in sequence
  init();
  run();
  destroy();
  Console.WriteLine("Ending Template Engine");
  }
 
  }

One thing that you should avoid is to make the template method virtual. Because it then gives the end user ability to override the template method hence changing the whole framework process flow.

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.

“Memory is like an orgasm. It's a lot better if you don't have to fake it.” - Seymour Cray