Design Patterns and System Architecture Study Notes-part of design patterns

Source: Internet
Author: User

Mode:

A specific environment, a problem, a solution

Core Idea: reuse design

Environment + problem + solution

 

Design Pattern: Describes custom objects and classes for each other, and solves general design problems in a specific environment.

 

Singleton mode:

Make sure that a class has only one unique instance and provides a global access point.

Solution:

The constructor declaration is called a private type, which is blocked by direct instantiation;

Only one instance class is controlled globally-static;

Provides a method for obtaining instances, which is used to return instances of the class and ensures that the same object is obtained;

(Whether the instance already exists. If the instance exists, return directly. If the instance does not exist, create a new instance and return it externally)

 

 

Closing principle:

Open to extension and closed to System Modification

Abstraction is the key to the principle of openness and closure.

 

Single responsibility principle:

High Cohesion Principle

Avoid sharing the same responsibilities (also called functions) to different classes;

Avoid a class from taking too many responsibilities;

Reduces coupling between classes;

"Discovering responsibilities" and "separating duties ";

Factory mode: Detach "CREATE" and "use" of an object"

Template Method mode: separation of "common function implementation" and "personalized expansion"

Command mode: Separate the "command requestor" and "command real-world"

 

Lee's replacement principle:

It mainly targets the inherited design principles;

Child types must be able to replace their parent types and appear anywhere the parent class can appear;

Subclass can extend the features of the parent class, but cannot change the original features of the parent class;

Principles:

Sub-classes can implement abstract methods of parent classes, but cannot overwrite non-Abstract methods of parent classes;

Sub-classes can add their own unique methods;

When the method of the subclass reloads the method of the parent class, the pre-condition (that is, the parameter of the method) of the method is looser than the input parameter of the parent class method;

When the subclass method implements the abstract method of the parent class, the post-condition (that is, the return value of the method) of the method is stricter than that of the parent class;

 

Dependency inversion principle:

Invert dependency to dependency Interface

Upper-layer modules should not depend on lower-layer modules. They all depend on an abstraction;

Parent classes cannot depend on child classes. They all depend on abstract classes;

Abstraction cannot depend on or depend on abstraction;

 

Interface isolation principle:

The dependence of a class on another class should be based on the smallest interface;

The client should not rely on interfaces not required by the client;

How to Avoid poor interface design:

Use multiple dedicated interfaces instead of a single summary port;

An interface represents only one role;

When you use the interface isolation principle to split an interface, you must first meet the single responsibility principle.

 

Merging reuse principles:

Also known as the principle of combination/aggregation reuse;

Try to use object combinations instead of inheritance for reuse purposes;

Existing objects are used in a new object through association (including combination and aggregation;

New objects reuse their existing functions by calling existing methods by Delegate.

Use combination/aggregation management as much as possible, and use less inheritance.

 

Dimit rules:

Require that a software entity interact with other entities as little as possible

 

(To be continued ......)

Design Patterns and System Architecture Study Notes-part of design patterns

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.