Object-Oriented Design (II) -- dimit principles

Source: Internet
Author: User

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. :

Figure (1)

Figure (2)

Figure (1) and figure (2) Analysis:

Figure (1) Why to figure (2? In this way, the coupling of classes can be reduced, which is equivalent to the appearance mode.

A software entity should interact with other entities as little as possible

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.