The author mentioned the mixed class in 1.6.4, but its description is very simple: the mixed class provides alternative interfaces or functions for other classes. It cannot be instantiated like an abstract class. The mixed classes require inheritance. The following class diagram is provided:
I think mixed classes are mainly used when different classes have some identical interfaces. The use of mixed classes not only improvesCodeThe reusability of the Code improves the maintainability of the Code.
Now we use a simple example to illustrate the advantages of mixed classes in code reusability.
For example, there is a personal financial processing system that collects statistics on a person's monthly income and expenses and displays them in the form of reports. We can write two abstract classes for income and expenditure: cincome and cexpenditure. Of course, we can add a createreport () method to the two classes to generate their respective reports. The class diagram is as follows:
In this case, we have to add the same createreport () method to both classes. However, once the report generation method is changed, we must modify the code of the createreport () method in the cincome class and cexpenditure classes respectively; if we have added the automatic report sending function for the system, we have to add a sendreport () method to the cincome class and cexpenditure class respectively. This not only wastes time but also reduces the maintainability of the Code. At this time, we can add a mixed class creport. The class diagram is as follows:
After the new inheritance system is adopted, you do not have to modify the cincome and cexpenditure classes if you have any changes to the report implementation functions or add any new functions. The use of mixed classes improves code reusability and maintainability.