Design Mode Introduction

Source: Internet
Author: User

Design Pattern Design Principles

Principle of opening/closing (OCP): It is open to extensions and closed to modifications.

Lee's replacement principle (LSP): Child types must be able to replace their base types

Dependency inversion principle (Dip): Dependent on abstraction, not specific

Interface isolation principle (ISP): Each interface is a type of role. There are not many roles that should not be done.

Dimit law (Levels)[Also known as the least knowledge principle (LKP)]: High Cohesion and low coupling (an object has as little knowledge as possible for other objects)

Synthesis/Aggregation Reuse Principle (Carp): Use merging/aggregation whenever possible, and do not use inheritance whenever possible

The classification of design patterns is divided into: Creation type: (it is related to the creation of classes and objects)

Factory method mode: Define an interface to create an object, but let the subclass decide which class to instantiate. Place the instantiation of a class to the subclass.

Abstract Factory Model: Provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.

Singleton Mode: Make sure that a class has only one instance and provides global access to the instance.

Builder Mode: Separates the construction of a complex object from its representation, so that different representations can be created during the same construction process.

Prototype: Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object.

Structure: (processing class and object combination)

Adapter mode:Converts an interface of a class to another interface that the client expects.

Decorator mode:Add more functions to an object dynamically.

Proxy mode:Provide a proxy for other objects to control access to this object.

Appearance mode:Provides a consistent interface for a set of sub-system interfaces.

Bridging Mode:Decouples abstraction and implementation so that the two can change independently.

Combination Mode:Multiple objects are structured in a tree to represent the local and the whole.

Metadata mode:Through sharing, we can effectively support a large number of small particle objects.

Behavior Type: (mainly describes how classes or objects interact and how responsibilities are assigned)

Rule mode:Define a series of algorithms, classify them, and make them interactive.

Template Method mode:The template method mode prepares an abstract class, implements some logic in the form of a specific method and a specific constructor subclass, and declares some abstract methods to force the subclass to implement the remaining logic.

Observer mode:Define a one-to-many relationship between objects. When an object changes, other related objects are notified and automatically refreshed.

Visitor mode:Encapsulate operations that are applied to a certain data structure element. Once these operations need to be modified, the data structure that accepts the operation can remain unchanged.

Iteration submodel:Provides a method to access each element in an aggregate object sequentially without exposing the internal representation of the object.

Responsibility Chain Mode:To cancel the coupling between the request sender and receiver, and enable multiple objects to process the request, you need to connect these objects into a chain and pass the request along the chain, until an object processes it.

Command mode:Encapsulate a request as an object so that users can parameterize the customer with different requests, queue requests or record request logs, and support cancelable operations.

Memorandum mode:A memorandum object is an object used to store snapshots of another object's internal state. The purpose of the memorandum mode is to catch the state of an object without damaging the encapsulation, and store it externally, in this way, this object can be restored to the stored state when appropriate in the future.

Status mode:When an object's internal state changes, its behavior also changes. The State mode creates a subclass of the state class for the possible states of each system. When the system status changes, the system changes the selected subclass.

Mediation mode:A series of object interaction methods are encapsulated so that these objects do not have to interact explicitly, so that they can be loosely coupled. When the roles of some objects change, the roles of other objects are not immediately affected, so that they can be changed independently.

Interpreter mode:Given a language, it defines a syntax expression and an interpreter that uses this representation to interpret sentences in the language.

By range:

Class Mode:It mainly deals with the relationship between classes and subclasses. These relationships are established through inheritance, which is static and determined at the Compilation Time.

Object Mode:It mainly deals with the relationship between objects. The runtime is variable and more dynamic. Most of the modes are object modes.

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.