General Introduction to design Patterns

Source: Internet
Author: User

1. Design Pattern classification.

Design patterns vary in granularity and abstraction levels, and are organized in an efficient way to facilitate reference to the relevant patterns of the various nationalities, while also facilitating the discovery of new design patterns.

Classification principle:

(1) The purpose of the code: according to the pattern is used to accomplish what work to divide.

Create type: Related to object creation.

Structured: Handles the combination of classes and objects.

Behavioral: Describes how classes or objects interact and assign responsibilities.

(2) Scope criteria: Specifies whether the pattern is used primarily for classes or for objects.

Class Pattern: Handles the relationships between classes and subclasses, which are established by inheritance and are static, and are determined at compile time.

Object pattern: Handles the relationship between objects, which can change at run time and are dynamic.

In a sense, almost all patterns use inheritance, so "class mode" refers only to those patterns that focus on the relationships between classes, and most of the patterns belong to the object schema.

2. How the design pattern is organized:

The Create class pattern defers partial creation of an object to a subclass, and the created object schema defers it to another object.

The structure class pattern uses the inheritance mechanism to assemble the class, and the structured object pattern describes how the object is assembled.

The Behavioral class pattern uses the inheritance description algorithm and control flow, and the behavioral object pattern describes how a group of objects can work together to accomplish tasks that a single object cannot accomplish.

There are other modes of organization in which some patterns are used together, such as: Composite and Iterator,visitor, and some patterns are replaceable, such as: prototype used instead of abstract Factory Some patterns, although using different intentions, have similar design results, such as: Composite and Decorator structure diagrams are similar.

Thinking about design patterns from multiple angles can help you understand their functions, differences, and applications in greater depth.

3. Design patterns How to solve design problems:

(1) Finding the right object

A customer request is the only way to make an object perform an action that is the only way an object changes internal data.

The most difficult part of object-oriented is the decomposition of the system into a collection of objects, because there are a number of factors to consider: encapsulation, granularity, dependencies, flexibility, performance, evolution, reuse, and so on, and they often clash with each other.

Object-oriented design supports many design methods, such as: (1) write the description of the problem, pick out nouns and verbs, and then create the corresponding classes and actions, (2) focus on the collaboration and responsibility of the system, (3) model the real world, and then transform the objects found in the analysis into the design.

Many of the objects designed are derived from real-world analytic models, but the resulting classes are usually not present in the real world, such as low-level classes such as group classes. The composite model introduces an abstract approach to the unification of objects that do not exist in the real world, and the models that strictly reflect the current real world do not exist to produce systems that can also reflect the future world.

Design patterns help you determine the abstractions and descriptions of these abstract objects that are not obvious. For example:

The object that describes the process or algorithm does not exist in the real world, but it is a key part of the design.

The strategy model describes how to implement an interchangeable algorithm family, which describes each state of an entity as an object that does not exist during the analysis phase or even in the early stages of the design phase, and is later explored to make the design more flexible and more reusable.

(2) Determine the granularity of the object

Objects vary greatly in size and number.

The design pattern describes what an object should be and how granular it is.

The facade mode describes how to represent complete subsystems with objects, and the Flyweight mode describes how to support a large number of minimum-granularity objects, and some other design patterns describe specific methods for decomposing an object into many small objects.

Abstract Factory and builder patterns produce objects that are specifically responsible for generating other objects; Visitor and command-generated objects are specifically responsible for implementing requests to other objects or groups of objects.

(3) Specifying an Object interface

The interface of an object describes a collection of all requests that the object can accept. When a request is made to an object, the specific actions that arise are related to the request itself and to the object being accepted, and different objects that support the same request may have different implementations of the action that the request fires.

(4) Implementation of the Description object

(5) using the reuse mechanism

(6) Structure of associated run time and compile time

(7) Design should support change

General Introduction to 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.