Dummit rules (lods): Also known as the least knowledge principle (LKP), that is to say, an object should have as little knowledge as possible about other objects.
In a narrow sense, The dimit rule:
If the two classes do not need to communicate with each other directly, the two classes should not interact directly. If one class needs to call the method of the other class, you can forward the call through a third party.
Disadvantages:
A large number of small methods will be created in the system, scattered in every corner of the system. these methods only transmit indirect calls, so the system has nothing to do with the business logic in the system. when the designer tries to see the overall architecture from a class diagram, these small approaches will be confusing and confusing.
In order to overcome the disadvantages of the narrow dimit Law, the dependency inversion principle can be used to introduce an abstract type reference "abstract stranger" object so that "someone" depends on "abstract stranger". In other words, is to turn "abstract strangers" into friends.
In the broad sense, the dimit rule:
An important sign of a module's design quality is the extent to which the module hides its internal data and implementation details.
The important reason for Information Hiding is that it can decouple subsystems so that they can be independently developed, optimized, read-and modified.
The primary purpose of the dimit rule is to control information overload. When using the dimit rule to design a system, pay attention to the following points:
* In terms of classification of classes, classes with weak coupling should be created. The weaker the coupling between classes, the more conducive to reuse.
* In the structure design of classes, each class should minimize the access permissions of members.
* In the design of a class, a class should be designed as a constant class as long as possible.
* When referencing other classes, the reference of an object to other objects should be minimized.
* Try to limit the valid range of local variables.