Principles of software design patterns)

Source: Internet
Author: User

The design pattern mentioned here is the pattern in software design, mainly refers to the object-oriented software design. Compliance with the design model can effectively improve the maintainability and reusability of software, improve the efficiency of software development, and avoid the phenomenon of too many re-engineering wheels.
 
The model is an abstract concept of the real world. The architectural model, design model, marketing model, and business operation model all have their own models.

The design pattern mentioned here is the pattern in software design, mainly refers to the object-oriented software design. Compliance with the design model can effectively improve the maintainability and reusability of software, improve the efficiency of software development, and avoid the phenomenon of too many re-engineering wheels.

My learning model is from the masterpiece "Design Model" of the top four people who know the name of the top, I really feel the many benefits that the design model brings to the software design. The content of "Design Patterns" is refined, with few instances, and my understanding is too poor. In actual learning, I learned it with jeffyyan's Java.

The principle of designing software is also the essence of the design model:

1. Open-Close Principle

1 ). the customer's requirements are unstable. by extending the existing software system, rather than modifying the software system, this software system meets the customer's needs, that is, the software system must be flexible and adaptive.

2) Existing modules, especially those at the abstraction layer, cannot be modified to ensure the stability and continuity of the software system.

The key to solving the problem is to abstract it and separate it from the specific implementation. Interface, an application of abstract classes

Encapsulation of variability: encapsulate variability into an object.

2. abstract class

The abstract class does not have instances. It is generally inherited as a Child class of the parent class and generally contains the common attributes and methods of this series.

Note: In a good inheritance relationship, only leaf nodes are specific classes, and other nodes should be abstract classes, that is, specific classes

Is not inherited. Share as much as possibleCodePut it in the abstract class.

3. Lee's replacement principle

Where a base class appears, subclass can be replaced.

When two specific class relationships violate the Li's replacement principle, one way is to abstract a base class as the parent class of the two classes,

One is to establish the relationship between application composite and aggregation relationships.

Do not misuse inheritance to use methods (functions) of some classes.

4. Dependency reversal Principle

Abstraction should not be dependent on details, but details should be dependent and abstract.

Programming for interfaces, rather than implementing programming.

PASS Parameters, or reference classes with high levels as much as possible in composite aggregation relationships.

We can dynamically create various specific objects when constructing objects. Of course, if some specific classes are stable, you do not have to create an abstract class as its parent class, this gives you the feeling of tongue-filling.

5 interface isolation principles

In the example of customized services, each interface should be a role, not many, and should not do anything that should not be done.

6 synthesis/aggregation principles

Use the principle of merging and aggregation as much as possible, and use inheritance with less caution.

Synthesis: The overall and partial life cycles are the same.

Aggregation: A part can be a part of the whole or exists independently of the whole.

Distinguish between has a and is

7 dumit's Law

Minimum knowledge principle. Do not talk to strangers.
 

Related Article

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.