At that time, I listened to a lecture on the design model, and some experience is here to share with you.
The lecture first starts from the object-oriented basic principle, the design mode is to provide a number of existing object-oriented solutions, so we must truly understand and use the design mode. You must first understand the object-oriented characteristics, that is, 1. Package package Divided into a primary package and secondary package, first-level package, a library function in the C language will perform some algorithms or common functions to make it reuse; secondary packaging, use the object-oriented characteristics to encapsulate function into components to facilitate reuse . It is advocated here that the secondary package is also encapsulated by the solution provided by the design mode to reach the component-level reuse. 2. Inherited inheritance is a traditional object-oriented reuse means, but inheritance is characterized by a hierarchical relationship and is highly coupled, so these features violate the design principles of high polymerization and low coupling, it is difficult to reuse. So advocate the combination of classes rather than inheritance to complete the function. From all design patterns, you can see the maximum number of two to three levels in the class diagram, and in the high-level interface. 3. Polymorphism is also called dynamic binding, which is not known to the specific use of specific uses, while it is known when running. To complete the polymorphism, you must use the interface or abstraction class, which is the core idea of object-oriented programming: interface programming. Here, it also mentioned that the difference between the interface and the abstract class: From the perspective of the design, the interface is facing the customer (may be the final customer may also be another subsystem), that is, the interface is the developer and A contract between customers, and the abstract class is an abstraction that completes the function during the internal implementation of the function, implements the external interface and provides the default implementation method to the internal implementation class. From the Java programming language, an implementation class can implement multiple interfaces, but only one abstract class (limited to Java single inheritance model), and additional abstract classes can provide partial implementation methods, and the interface does not have any ways Realization. This should be used to understand from the design angle without simply look at a programming language (like C does not have an interface keyword, but this does not affect C implementation). 4. Abstract everything in the object-oriented idea can be an object, so appropriate abstraction is also an important idea of object-oriented. Some objects are corresponding to a specific thing in the real world. At this time, it is better to understand, but sometimes it is more abstract, such as: the current state of the system, a system of the system, in fact, these are also objects. Just like the State, Command mode mentioned in the design mode.
Due to the relationship of the space, I will no longer tell the specific mode, understand and use the design mode to pay attention to the following points: 1. True understanding object-oriented characteristics; 2. Matprate each design mode, reach someone to mention a model The name, immediately reflect the class diagram of the pattern in the mind; 3. Use the designed model that has been mastered as much as possible, so slowly understand the essence of each pattern. 4. The mode is to provide an existing solution is used in design, which means not to see the mode from the code. That is to say, from top to bottom (from design to encoding). In addition, there is also a reference to refactor in the extreme programming (XP), and the reconstruction is precisely, and it is from the down to the top of your code. Interested, you can refer to 6