1. The maintenance of the software's maintenance and reused software is the regeneration of the software. System design goals: scalability, flexibility, insertibility. Scalability: New features are easily integrated into existing systems without affecting other modules of the system. Flexibility: Allow code to modify smoothly. This will not affect the other when you modify one place, which reduces the cost of maintenance. Insertability: It is easy to replace the already existing classes with a class. As long as the interface is consistent, change the implementation class does not affect the user. Software reuse can improve software productivity, and proper reuse can improve software maintainability. Previously, multiplexed is mainly code, functions, and structural multiplexes, and now multiplexes primarily for classes, interfaces, components, and more. But multiplexing does not necessarily guarantee the maintenanceability of the software. It is not necessary to reuse because of the reasons such as code, and it is necessary to analyze according to specific situations. To enhance the maintenanceability of your system by multiplexing, you must ensure that multiplexing is supportable to support maintainability. Some of the design principles below can be used to guide practice. 2. Open-Closed Principle (OCP) opening and closing principle is an object-oriented cornerstone. It mainly refers to: A software entity is open to the extension and is turned off for modification. When designing a module, it should be that this module is expanded without modification. The system that satisfies this principle is reused at a higher level and is easy to maintain. How can we meet the principle of opening and closing? Abstractization is the key. To distinguish the disconnection layer and the realization layer. In a software system, the abstraction layer should be relatively stable, and the realization layer can be changed and expanded. The opening and closing principle is also the principle of encapsulation of variability. Find the variable factor of the system and encapsulate it. Package a variability into an object, then this variability different appearance is the specific subclass of this class. 3. The Principal Rehabilitation Principle (LSP) The principle of replacement is the inherited cornerstone: where any parent class can be replaced with its subclass. For example, squares and rectangles. Square is a special rectangle. However, the square cannot be used as a subclass of rectangles. Due to rectangular operations, it is not necessarily available on square. Such as: resize (). If the square is a rectangular subclass, there will be many problems. Do not meet the principle of replacement, the square cannot be used as a rectangular subclass, and the square and rectangles should be used as a quadrilateral subclass. This is a very important principle when the classroom architecture is designed. Should not be used as a subclass. 4. Dependency reversal principle (DIP) relying on the reverse principle is: to depend on abstraction, do not rely on specific implementation. Why is the principle of relying on the reversal? In a conventional process system, the high-level module depends on a low-level module, and the abstraction hierarchy depends on the specific level. This results in any change in the bottom layer affects the upper layer. Such a software system is not maintainable. Abstract hierarchies should not rely on specific implementation details, so that the system's reuse and maintainability, this is the so-called reverse. How do I apply this principle in actual? To programs for excuses, not for programming. Then when you achieve changes, you will not affect other places. In Java, you should use the interface and abstraction class to perform variables, the type declaration of the parameters, the return value of the method, and so on. For example, List List = New LinkedList (); coupling in an abstract manner is the key to relying on the reversal principle. In accordance with the principle of relying on reversal, a large number of classes, such as abstractions and interfaces, because it assumes that all classes are possible. But actually this is not always correct. There are some specific classes that are very stable, and it is not necessary to invent a new type of inventions. 5. Interface Isolation Principles (ISP) Use multiple special excuses to always be better than using a single total interface. An interface should only represent one role without encapsulating all the operations into an interface. Accurately divide the roles and the interfaces thereof, should not merge the interface without the relationship.
6. Synthesis / polymerization reuse principle aggregation: indicates the relationship between the owned or overall and part. Synthesis: stronger aggregation relationship. The life cycle of the overall responsibility, the whole, and part is unsurable, and the part cannot be shared. For example, Sun Wukong, his limbs, and his weapons. The relationship between Wukong and the limbs is synthesis, and the relationship between weapons is aggregation. In object-oriented, there are two basic methods for inheritance and synthesis / aggregation. Synthesis / Aggregation is a function that will have an existing object as its own member, new object call object existing. This has many advantages: 1) This multiplex is a black box operation, and the details of the members object are encapsulated. 2) This multiplex can be dynamically changed, and the new object can be dynamically referenced by other similar objects. Inheritance has the following advantages and disadvantages. 1) It is easy to implement. 2) Inheritance retrieving the packaging, exposes the superior implementation details to the child class. 3) At the same time, if the superclass changes, the subclass has to change. 4) Inheritance is static. Try to use and become / polygitations instead of inheritance to achieve multiplexing. And distinguish between these two relationships, distinguishing between "HAS-A" and "IS-A". Correctly distinguish between the two multiplexing methods to be used correctly. For example: people and characters. Inheritance, each role can be used as a child class. Such as students, employees, managers, etc. But inheritance is static, once a person has a role, you can no longer have another role. For example, a person is a manager, but it is also an employee or a student. This is obviously unreasonable. The synthesis / polymerization of the synthesis / polymerization should be adopted. In fact, people and roles are "HAS-A" rather than "IS-A", and only the relationship between "IS-A" can only be made when the Riches replacement principle is satisfied. In the Java API, Properties inherits HashTable. Proterties have all behaviors of Hashtable. In fact, Properties is not a HashTable at all. More seriously, the Properties can be transformed into HashTable, bypassing the Properties interface, calling the HashTable method to operate the Properties, which causes the internal contradiction and crash of Properties. They can be "HAS-A", but they cannot be "IS-A" relationship. In practice, it will never abuse inheritance because of the multiplexing of code and function, and must meet the principle of replacement of the Riviera. 7. Dimit France (LOD) Dimit France: An object should understand other objects as little as possible. Here are some representations: 1) Communication only with your direct friends 2) Don't speak with strangers. 3) Each software unit has only the least knowledge of other units. Its purpose is to reduce the coupling of each unit and improve the maintenanceability of the system. Between the modules, its communication should only communicate with each other's API, and ignore the internal working principle of the module. It can minimize the degree of coupling of each module to promote the reuse of software. This is my first reading note, which is inevitable to have errors and omissions. I hope everyone will give you a lot of advice! !