Encapsulate complicated and frequently changing modules in the system.
The advantage of abstraction is that you can ignore irrelevant details during design. The method to encapsulate the complexity that helps you manage the system is to prevent you from seeing the complexity. When designing a class, you should develop a habit. Ask yourself "What fields and functions should I hide" and you will be surprised to find that there are many difficult design problems that will be resolved in front of you. One of the most important challenges for good programming is adapting to changes. The goal should be to isolate unstable areas. So as to limit the impact to a sub-program, class, or package. The method is: 1. Find out the modules that seem easy to change. 2. Separate easy-to-change modules. Separate easy-to-change components into classes. A class interface is designed to restrict changes within the class without affecting the exterior of the class. Any other class that uses this will change will not notice the existence of the change. The following lists areas that are easy to change: 1. Business Rules, such as business logic processing, do not need to change the business logic even if the interface framework is changed. 2. Hardware-dependent isolation is very helpful for Porting Programs to new hardware environments. It is also convenient for you to test the system module. For example, when the hardware function module is not stable, you can use the software as a simulator to simulate the hardware input and output to replace the hardware and continue development. When the hardware is available, connect with the software. 3. Text storage is used before the storage of input and output data, and then changed to data storage. 4. Non-standard language features such as the third-party framework used in your system may be discarded in the future, then you should use a separate class or sub-module to encapsulate calls to these third-party frameworks. 5. Difficult designs isolate modules that are poorly designed and need to be re-designed to minimize the potential impact on the rest of the system. 6. Complicated design encapsulates complicated algorithms, because the probability of a complex module error is relatively high, the probability of optimization is very high. This is similar to the fifth article. 7. State Variables use enumeration instead of Boolean variables to describe the state variables. When a Boolean variable is used for definition, it is often found that, in addition to true and false, other States are required. The value of the access status of the accessors subprogram is used instead of the direct check of the status variable. 8. Restrictions on data volume. For example, when defining an array with 100 elements, some information that is not required to be known to the outside will be disclosed, which will increase the complexity of understanding the system. The constant max_length should be used to hide the data. Source: http://www.cnblogs.com/zhuojun/
Codenong small manual 1