What is the Demeter principle? What role does the dimit principle play in class design?
Demeter principles
1. Definition: each software unit has only the minimum knowledge of other units and is limited to software units closely related to the unit.
2. Analysis
(1) The Demeter law means that a software entity should interact with other entities as little as possible. In this way, when a module is modified, it will affect other modules as little as possible, and expansion will be relatively easy, which is a limitation on communication between software entities, it requires limiting the width and depth of communication between software entities.
(2) The dimit law in a narrow sense: it can reduce the coupling between classes, but it will add a lot of small methods to the system and scatter them in every corner of the system, it simplifies the local design of a system, because each part is not directly associated with a remote object, but it also reduces the communication efficiency between different modules of the system, this makes it difficult to coordinate different modules of the system.
(3) in the broad sense, the dimit rule refers to the control of the information traffic, flow direction, and information impact between objects, and mainly controls information hiding. Information Hiding decouples subsystems, allowing them to be independently developed, optimized, used, and modified, while promoting software reuse, because each module does not depend on other modules, each module can be used independently in other places. The larger the scale of a system, the more important information hiding is, and the more important information hiding is.
(4) The primary purpose of the dummit rule is to control information overload.
Guiding Ideology:
1. in terms of classification of classes, we should try to create loosely coupled classes. The lower the Coupling Degree between classes, the more conducive it is to reuse. Once a class in loose coupling is modified, does not cause too much impact on the associated classes.
2. In the structure design of the class, each class should minimize the access permissions of its member variables and member functions.
3. In the design of classes, as long as possible, a type should be designed as a constant class.
4. When referencing other classes, the reference of an object to other objects should be minimized.
Instance
I. The call relationship between a system interface class (such as form1 and form2) and a data consumer class (such as dao1 and dao2) is more complex. :