Basic framework elements of high reusable software architecture

Source: Internet
Author: User

Interfaces are the basic framework elements and important components of high reusability software architecture. It seems that the importance of interfaces is exaggerated, but this is not the case.
The C ++ framework that was first favored by most programmers in window development was Borland's built-in Owl (Object window Library) in Borland C ++ 1992 in 3.1 ), early C ++ developers should be very familiar with this development framework. Borland owl has been brilliant. However, we will not discuss it in depth here. We just use owl to illustrate the role of interfaces on the high reusability software architecture. When we use owl to automatically generate the application framework code, we will get the main program code similar to the following (we haven't used owl for a long time, and we can't remember the details of the Code, but it does not affect our discussion ):
Int main (INT argc, char * argv [])
{
Tapplication * Application = new tapplication (argc, argv );
Try
{
Application-> Init ();
Application-> Run ();
Application-> done ();
}
Catch (...)
{
// Todo: Add catch code here
}
Delete application;
Return 0;
}
The structure of the main program is obvious. First, create a pointer to the application object, then call the init method to initialize the program, and call the run method to execute the program body; call the done method to scan the program before it ends. Finally, use the delete keyword to delete the application object pointer.
The above code is non-reusable code, and the entire business logic of the program is completely hardcoded in the tapplication class. That is to say, for the above Code, if you need to modify the business logic of the system, you must change the program, and then re-compile, run, and test.
This problem is actually obvious. The solution to the problem is to use an interface (called a virtual base class in C ++) to implement the interface through a specific class that implements the business logic, classes that implement specific interfaces are instantiated in the main program to achieve dynamic loading and configuration of business logic.
The above code is still discussed. If we use the virtual base class, the program will have another scene, for example:
Class iapplication {
Public:
Iapplication (){}
~ Iapplication (){}
Public:
Virtual void Init () = 0;
Virtual void run () = 0;
Virtual void done () = 0;
};
Then let the application's business processing subject class inherit the iapplication class and implement the pure virtual function:
Class tapplication: Public iapplication {
Public:
Tapplication (): iapplication (){}
~ Tapplication (){}
Public:
Virtual void Init (){//...}
Virtual void run (){//...}
Virtual void done (){//...}
};
Then modify the main function:
Int main (INT argc, char * argv [])
{
// The application in the downstream is of the iapplication * type, not the tapplication * type in the previous example.
Iapplication * Application = new tapplication (argc, argv );
Try
{
Application-> Init ();
Application-> Run ();
Application-> done ();
}
Catch (...)
{
// Todo: Add catch code here
}
Delete application;
Return 0;
}
On the surface, it seems that it is no different from the original program. However, if we use the factory mode in the main program to create different application business processing classes under different application parameters, then our program will become reusable. We do not need to modify the main program or even the business logic processing class when new business logic appears, we can make the new business logic processing class inherit from the existing business logic processing class, or inherit from the virtual base class (such as the iapplication class in the above example), and then give the running parameters of the main program, this allows the program to run according to the new business logic.
The above example provides the most common example to illustrate the important role of interfaces (virtual base classes) in the high reusable software architecture. We can imagine that for a complicated software system, if we define all the business logic processing components as interfaces, all business logic processing components of the entire software system will be reusable. In fact, the main task of the software architecture is to define interfaces reasonably. The relationship between these interfaces and interfaces will become the skeleton of the software system. In architecture, the structure of a house has the Framework Structure and the load-bearing wall structure. Therefore, the software architecture is to reasonably define the interface and the relationship between them and build the Framework Structure of the software system. Therefore, interfaces have become a basic framework element and an important part of the high reusability software architecture.

Http://www.sunnycrystal.net/ShowDocument.aspx? Id = 19

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.