Also on the design of object-oriented system functions

Source: Internet
Author: User

Many netizens wanted me to introduce some experience in programming and development in the process of writing my program. As I have said before, although I am also a computer professional, many things are not learned from the teacher at school, but summed up after failure in my work. As to whether the summary is the best and most suitable, I don't know. I only know that in my current system development process, it still plays a role. In this article, I would like to briefly introduce some of my ideas and models in terms of system function design, and hope to serve as a reference for everyone. If you have a better method, please leave a message for us.

 1. System design objectives

Encapsulation: High Cohesion, low coupling

Encapsulate modules to facilitate reuse and minimize the impact of module changes.
Scalability: Potential functions and interfaces for future extension should be considered. Consistency: Including the consistency of the module design and the consistency of the same module in different systems
The consistency of the module design requires that each module adopt a consistent design idea to simplify the design replication and improve readability and maintainability. 2. Key Points of system design Perfect but not gold platedYou must have a mentality of pursuing perfection, but it cannot be plated. Note the 80: 20 principle. We strive to use 20% of the cost to achieve 80% of the functionality, instead of using a large amount of time to solve non-key problems or low probability problems.
Empathy and consideration from the user perspectiveEspecially for the interface design, including the display of graphics and content. It should be considered as a user. Simple operation, beautiful interface, stable and efficient.
ResponsibilitiesUnderstand the meaning of classes and modules, and clarify the responsibilities and roles of each class and module. Do not do jobs that do not belong to it. Once there is a job that should not be completed by this class, it means that your module already has defects.

3. System Framework Structure

The specific functions of each part are described in the following sections.

4. MFC basic responsibilities

The basic MFC classes include application classes, main framework classes, view classes, and document classes. The application class is responsible for system initialization, including checking the validity of the configuration file information, whether the database can be correctly connected, and whether the system is registered to determine whether the system needs to be started;
The main framework class manages tool bar, status bar, menu bar, and floating form, and serves as a transfer station for sending and receiving messages throughout the project. The floating form will be used as a container, the information display and interaction windows of each module are integrated on the tab page, so that the entire system can effectively manage windows, so as not to see the phenomenon of floating windows flying over the sky.
The View class is responsible for responding to users' mouse and keyboard events and posting users' actions to the corresponding entity module management class based on the current operation status. And draw the results in the view. For the view, remember the principle that it is only responsible for information interaction, including receiving various inputs and displaying relevant information, no business-related processing is required. All business-related processing must be handled by the management class of each business module. The document class records instances of object classes. Currently, the functions of document classes are relatively weak, and they are barely responsible for the management of business module objects.

5. Composition of independent modules

Each module includes a management class, an information window class, and several entity classes. The management class encapsulates the interaction between object-class objects and the outside world, receives and schedules mouse and keyboard events transmitted by view classes, and similar management classes and view classes from the abstract layer, it is a "View class" in the business module. It is responsible for receiving external requests to the module and returning the processing results of the business module's external requests. The information window class is used to display information of object class objects to users in the form of data or graphics, and receive user input. The entity class expresses specific module businesses, it can be divided into more specific sub-modules as needed. The information window class is strongly correlated with the management class, and the information window class is a friend class of the management class. Both the management class and the information window class serve as auxiliary objects of the business module. In principle, they are regarded as dependent on the business module class. Therefore, the two are regarded as a whole. 6. Message MechanismTo reduce the coupling between classes, messages are used to transmit information between classes. Messages sent to a view or floating form can be forwarded through the main framework class, which avoids strong binding between the object class and View class and floating form class. In order to avoid the direct introduction of View class and other class objects of the current project in the business module, resulting in strong association between the business module and the current project, messages of all business modules are sent to the main framework class, then, the main framework class is responsible for forwarding to various display windows, such as views and floating windows, which are managed by the main framework class. To support some specific functions, the system adds a similar message reflection mechanism. If the mouse event of a view sent to a specific module class does not have specific operations or changes, the event will be sent to the view through a message so that it can be processed by default. 7. Module DesignA module can be divided into several physical and logical classes. Physics is responsible for encapsulating data and directly reading, writing, and processing data. Logic is responsible for managing and scheduling physics.
The physics class can be abstracted to form the base class and fully utilize the object-oriented method to design the class. Clarify the rights and obligations of each category and do not do the work that does not belong to it. This can be compared with the company's management structure.
The member variables and methods of the class must be clear as public, protected, or private. The member variables should provide methods to encapsulate read/write operations. The above is basically a set of system function design models developed by the author over the years, which have been applied in the author's project practices. The cost for migrating and replacing modules is low. Because all modules have good consistency, new employees can also master the system structure in a shorter period of time. Of course, this is just a single point of view. Please give me more comments.

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.