Summary of design patterns (II)

Source: Internet
Author: User

1. Strategy Mode VS simple factory

A simple factory is only a production object,

The policy mode is to use specific methods for production Objects Based on different objects at the same time.

2 Principles

(1) single responsibility

(2) reverse dependency

Abstraction should not depend on details. Details should depend on abstraction.

Interface Programming rather than real-world Programming

(3) Open and closed

Scalable, not modified

(4) dimit's Law

The less you know, the longer you live.

3 factory method mode VS simple factory Mode

A simple factory model is a unified large factory.

Factories in the factory model divide large factories into abstract and specific factories.

4. template mode VS prototype mode

The inheritance of the template mode, the overall architecture remains unchanged.

The template method allows the subclass to redefine certain steps of an algorithm without changing the structure of an algorithm;

The prototype uses the clone function to create another custom object from an object without any details.

5 builder mode VS decoration Mode

The builder Mode means that the conductor uses different methods (but the process is the same) to create an object.

The decoration mode adds different functions to an object.

6 builder mode VS template Mode

The builder mode adds a conductor Based on the template mode.

7. Delegate (in observer mode) VS proxy Mode

A delegate is a special proxy. A delegate is a method that can have parameters and return values.

Proxy is an object.

The essence is to do things for others.

8 proxy mode VS appearance Mode

The proxy object represents a single object and the appearance object represents a sub-system;

The customer object of the proxy cannot directly access the target object. The proxy provides access control for the individual target object, while the customer object of the appearance can directly access each object in the subsystem, however, the appearance Object usually provides a simplified and common interface for calling the functions of each component of the subsystem.

Proxy VS Adapter

It is actually a cohesive feature. Proxy is a representative of the original object. Other operations that need to deal with this object are negotiated with this representative. The adapter does not need to create a representative. It only needs to combine the original classes for specific purposes.

9. Bridge Mode VS adapter Mode

Bridging and adapter share some common characteristics, that is, to provide a certain degree of indirect property to another object, which is conducive to the flexibility of the system. However, we can't wait until the problem occurs to solve the problem. Instead, we should think about how to avoid the problem at the beginning of the design. Bridging is usually at the beginning of the design, bridge the abstract interface with its implementation to allow the abstraction and implementation to evolve independently.

They each have their own advantages. It cannot be said that at the beginning of the design, it must be better than making up for it after the design. In fact, in reality, two classes have already been designed, and they need to have a unified interface later, there are also many cases of integration. Therefore, bridging and adapters are used in different stages of the software life cycle. They are aimed at different problems, not to mention the advantages and disadvantages of bridging.

10 appearance mode VS adapter Mode

They are all encapsulation of existing systems. Some people say that the appearance is actually the adapter of another set of objects. This is inaccurate because the appearance defines a new interface, while the adapter is to reuse an original interface, the adapter is to make two existing interfaces work together, and the appearance is to provide a more convenient access interface for the existing system. If the appearance is adaptive, the adapter is used to adapt to the object, while the appearance is used to adapt to the entire subsystem. That is to say, the appearance is more specific to objects.


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.