Library tutorials & articles

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

Comments

  1. 30 Nov 2005 at 02:20
    None serious actual framework uses inheritance or templating. Inversion of Control (aka Dependency Injection Pattern) is a much better design and seems to be the way most popular frameworks had taken.
  2. 10 Feb 2003 at 07:39

    Developing Java for a few years and understanding most of the concepts and theory of the language this tutorial gave me a better idea as to what to expect when making the jump to C#.  Although not in-dept, intricate enough to get the 'just' of the language and framework building.  EXCELLENT JOB!!!!!!!

  3. 06 Jan 2003 at 14:58

    The title gives an impression that we are going to delve deep into application frameworks...but the article is just basic, although its OK.  Better change the title to avoid such comments.

  4. 18 Dec 2002 at 17:04
    Horrible!!

    I thought this was an article about Frameworks??? Instead I get a brief on the basics of Inheritence. A Framework is a much larger issue, and cannot be covered in three HTML pages.


  5. 02 Jul 2002 at 08:53

    A very good article and written in a very good understandable form.
    Frameworks are rightly easing the amount of effort required to put in to code development by developers.
    Frameworks provide set of services , but dot NET goes beyond that by managing the code that uses those services. So, dotNET can be viewed as playing dual role (Provision of services and managment of code).



  6. 01 Jan 1999 at 00:00

    This thread is for discussions of Building Application Framework with C#.

Leave a comment

Sign in or Join us (it's free).

Nauman Laghari

Related podcasts

  • Object-Oriented Programming in Ruby

    In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...

Want to stay in touch with what's going on? Follow us on twitter!