Application framework with C # development program

zhaozj2021-02-17  74

Application framework with C # development program

WillSound (willsound@163.com)

Introduction:

The framework is a customized general application development base software, which can develop complete and complete software. In recent years, there have been successfully realized development frameworks in some applications, such as user interface development and data access development. If you can successfully develop a framework, this will be a breakthrough, because this means that development will no longer implement a feature from the beginning: such as a framework if you can successfully generate a user interface, which can also generate any arbitrary User interface. For example, if we use Java Applets and Servlets, we only need to rewrite certain methods, you can implement our own code. This java applets and servlets are the framework platform we use. Microsoft also implements MFC inventory, as well as .NET Framework (of course also used Borland's VCL).

prerequisites:

The readers in this article should have C #'s experience, or have a foundation understanding of Java Applet and Servlet so that some of the basic concepts involved herein.

tool:

The code written in this article is tested under the Windows 2000 .NET Framework release. Because this article does not require a graphical interface, I use the writing board and the C # command line compiler.

text:

Below, you will see how to implement an application framework model. The basic core when developing the application frame is the Template method, which is hidden in the application, controlling the operation of the application. It is only implemented in the base class and cannot be changed.

The first step is to build the base class of the frame. The base class is the most important class when building a framework.

It has methods that can be rewritten, and end users can rewrite these methods to implement their own applications. In addition to this, there is a Template method for controlling in the framework process. The framework we will build includes three abstraction methods that require end users. They are init, run and destroy. They must be in order. Below is the code we implemented.

// This class is defined as an abstract class because the user approach has not been implemented.

Abstract Class Appframework

{

// Constructor Call Template method

Public appframework ()

{

TemplateMethod ();

}

// The following method requires an end user implementation

Public Abstract void init ();

Public Abstract void Run ();

Public abstract void destroy ();

// Template method is the core of the framework

Private void templateMethod ()

{

Console.WriteLine ("Initializing Template Engine);

// Template method sequential call required

INIT ();

Run ();

DESTROY ();

Console.writeline ("ending template engine");

}

}

Please do not write the template method as the false method, as this will give the end user to modify the ability of the Template method to change the basis of the entire framework. That is, this is only the task that needs to be completed. The end user is to do inherit from the framework base class and rewrite these abstraction classes defined in the framework to implement their own customization.

/ / Inherit from the base class

Class myclass: Appframework

{

// Rewrive the abstract method to achieve custom functions

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 the main () function is feasible in a class, it is preferably placed in a separate class. Here is all code.

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

}

}

转载请注明原文地址:https://www.9cbs.com/read-31225.html

New Post(0)