Application frame design
License
First, summary
With the development of object-oriented technology, many famous application frameworks have emerged, such as MFC, VCL, OWL, etc. under Windows platform; there is Turbo Vision under the old DOS system. Here I wish to explain my idea of designing application framework through the "SW system" I designed. The contents involved are mainly:
1. Basic content of the application framework design
This part is mainly to discuss the necessity, feasibility, feasibility, and basic ideas for designing application frameworks.
2, the overall content and implementation of the SW system
This part mainly discusses the overall structure and content of an application framework, SW system, and describes some important implementation details for SW systems. The main features: Window models, attributes, SW systems in the SW system, and sequences, etc. In the end, we have to analyze the defects of the classic application framework. It also illustrates the inevitable inevitable from the SW system to the COM.
3, the new direction of the SW system: Application framework based on COM (Component) Thoughts
This part mainly introduces the basic content of component ideas. The SW system is implemented for component ideas.
Second, the basic content of the application framework design
How many "bones" is there in an app, how many "meat"? The "meat" mentioned here is the part of the process used to solve the problem, and "bones" refers to the program framework of the "meat", and they are interacting with users, making the interface friendship must do. .
For the logic of solving the problem, we can hardly find a general practice to simplify this matter. This is only possible to do this only when it is specifically positioned to a specific direction. For example, you have to make a numeric calculation, you may need a full-functional mathematical package; you have to image processing, you may need an image processing library; etc. Strictly speaking, these things are not a framework, just a toolkit (Utilities). Because they generally have no complex call rules, the function is quite independent.
For applications and users, those programmed in the DOS era must have a deep touch. The action of the DOS period is basically the interaction with the user is completed. The result of this is often not feeling that there is too much time in the interface design, that is, I feel that the interface is not satisfactory. The frame code of each program has a lot of repetitions, but due to the limitations of the programming method, the reuse efficiency of the program code is often relatively low.
The maturity of object-oriented ideas has prompted the birth of various application frameworks. Object-oriented language, the success of the class can complete the reuse of a large number of ready-made code reuse; dynamic beam (ie, virtual function mechanism) technology effectively delays the specific implementation code to the design phase. A application structure called "Event Drive Mode" completely separated the framework code of the program and the details of the implementation. Although there are quite a lot of application frameworks, they are considerable in realization: all of these application frameworks are an application of "event-driven mode". This also includes the SW system to be described herein.
The core of "event-driven" is natural is an event. From an event perspective, the basic structure of the event driver is composed of an event collector, an event transmitter, and an event processor. The event collector is responsible for collecting all events, including from users, such as mouse, keyboard events, etc.), from hardware (such as clock events, etc.) and from software, such as operating systems, applications themselves, etc.). The event transmitter is responsible for distributing events collected by the collector into the target object. The event processor makes a specific event response work, it is often necessary to fully determine the implementation phase, so you need to use the virtual function mechanism (the function name tends to be taken to a name similar to the HandleMSG). For the user of the frame, they only see the event processor. This is also what they care about.
View (ie, what we usually say "window") is another elevation of the "event-driven" application. It is the target object of the event transmitter we said. The view accepts events and can be processed. When we send an event to a specific view, we actually complete a fundamental change: from the traditional streamlined program structure to the transition of the event trigger mode. This application has considerable flexibility, which can cope with all kinds of discrete, random events. Since Windows itself is based on an event-driven model. Therefore, it is considerable to implement the application framework under the Windows operating system. In the basic unit of the event driver, the event collector has been completed by the Windows system; the event transmitter has also been completed by Windows. The reason why it is partially because Windows is implemented in C language instead of C . Since there is no object, Windows sends events to so-called "Window Functions" (although not sent to specific objects, it should be said that this is a variant that is object-oriented). Thanks to Windows to do this. It is possible to exceed our imagination to determine the complex work to do. We have to qualitatively discuss this.
According to the transmission route of the event, the event can be divided into the following:
1) Location event (mouse event)
Its goal is more clear, that is, the view containing the point where the mouse is located. However, this is not applicable. At the time of dragging, the recipient that is often desired to be the mouse message is a view that the mouse is just dragging, not that the view that is really included in the mouse point. It is to consider this, Windows proposes the concept of "capturing mouse messages".
2) Focus events (keyboard events, command events, etc.)
For focus event messages, the situation is more complicated. In order to understand this, you need to introduce concepts such as modal view, focus view.
A view structure of an application is usually maintained by a tree structure. At some point, there is always a view that all ancestors are no longer accepted, while it and all their subviews still handle events. This view is called a modal view. It is called "active roots". A typical example of a modal view is a dialog. At its runtime, the other parts of the application have lost responses.
What is a focus view? Modal view is first a focus view. In the subview of the modal view, there is a view that is activated (or said, it gets "focus"), it is also a focus view. If it is also a composite view (a view of the child view), it can also have a sub-focus view. This logic has been an activated simple view (for it, there is also a name, called "Hot View"). All parent views of the "Hot View", parent view of the parent view, etc. until the modal view, constitute a "focus view" chain.
In general, the focus event first sends a current modal view. When it doesn't know how to deal with, it may pass the event to the focus view chain. Many people often find that an event handler is always unable to be executed. This situation always occurs in focus events. The reason is that the ancestral view has intercepted the event. If the process of passing the event is understood, how to rewrite the code is clear.
However, there are too many exceptions on focus events. Some views are not focusing, but also want to process the keyboard message. Typical examples are some buttons in the menu, and some buttons in the dialog. There are already some operational practices for these Windows, and Windows is also impossible to fully determine the target view.
3) Broadcast event
Broadcast events don't know their goals, its processing is simple, it sends events to all views. WINDOWS does not support broadcast messages. The SW system implements broadcast messages mainly for logic simplification, such as closing all windows, saving all files, etc., the concept of applying broadcast is convenient.