C# object-oriented design principles (6) Dimit's rule

Definition of Dimit's Law:

0. Talk only to your immediate friends and not to strangers (Talk only to your immediate friends and not to strangers)
1. Also known as the'Minimal Knowledge Principle'
2. If two software entities do not need to communicate directly, Then there should be no direct mutual call, and the call can be forwarded through a third party. Its purpose is to reduce the coupling between classes and improve the relative independence of modules.

Advantages of Dimit's Law:

1. Lower the coupling degree between classes and improve the relative independence of modules .
2. Due to the reduced affinity, the reusability of the class and the scalability of the system are improved .

The implementation of Dimit's law:

1. From the perspective of the dependant, only depend on the objects that should be depended on.
2. From the perspective of the dependent, only expose the methods that should be exposed.

Guess you like

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