The law of the level of detail

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.