C# object-oriented design principles (7) composition reuse principles

Definition of composite reuse principle:

1. It is also called the principle of combination/aggregation reuse
. 2. It requires that when software reuse, it is necessary to use combination or aggregation as much as possible to realize it first, and then consider the use of inheritance.
3. The composite reuse principle and the Richter substitution principle are complementary, and both are the specific implementation specifications of the open-close principle.

The importance of the principle of composite reuse:

1. The coupling between the old and new classes is low. This kind of reuse requires fewer dependencies, and the only way for new objects to access component objects is through the component object's interface.
2. It maintains the encapsulation of the class. Because the internal details of the component object are invisible to the new object, this kind of reuse is also called "black box" reuse.

The realization method of composite multiplexing:

1. The principle of composite reuse is achieved by incorporating existing objects into new objects as member objects of the new objects. The new objects can call the functions of existing objects to achieve reuse.

Guess you like

Origin blog.csdn.net/MrLsss/article/details/109309649