Design Pattern)

Source: Internet
Author: User
The design pattern describes a general solution to a certain type of common problems in the software design process.
The object-oriented design mode describes the Organizational Relationship between classes and objects that communicate with each other. The purpose is to cope with changes, improve reuse, and reduce changes.
Generally, a design model has four basic elements:
Pattern name is a nickname. It uses one or two words to describe the pattern problems, solutions, and effects. Naming a new pattern adds our design vocabulary. The design pattern allows us to design at a higher abstraction level. Based on a schema vocabulary, we can discuss patterns between ourselves and our colleagues and use them when writing documents. The model name can help us think about it, so that we can exchange design ideas and design results with others. Finding the proper pattern name is also one of the difficulties in designing pattern cataloguing.
Problem describes when to use the mode. It explains the causes and consequences of design problems and problems, and may describe specific design problems, such as how to use objects to represent them. Algorithm . It may also describe the class or object structure that leads to inflexible design. Sometimes, the problem part includes a series of prerequisites that must be met by the usage mode.
The solution describes the components of the design, their relationships, their respective responsibilities, and their collaboration methods. Because a pattern is like a template and can be used in many different scenarios, the solution does not describe a specific and specific design or implementation, instead, it provides an abstract description of the design problem and how to use a combination of general elements (class or object combination) to solve the problem.
Consequences describes the effect of a pattern application and the trade-off between the usage modes. Although we do not always mention pattern effects when describing design decisions, they are important for evaluating design choices and understanding the cost and benefits of patterns. Most of the software results focus on measuring time and space. They also express language and implementation problems. Because reuse is one of the elements of object-oriented design, the pattern effect includes its impact on system flexibility, scalability, or portability, listing these effects explicitly is helpful for understanding and evaluating these patterns.
The design patterns: the basis for reusable object-oriented software book describes 23 classic object-oriented design patterns, and creates the role of patterns in software design, the four authors of this book are referred to as Gang of Four (gof) and "four-person group". The 23 classic design patterns described in this book are also referred to as gof23 design patterns. These 23 design patterns are divided into three categories by objective: Creation Mode, structure mode, and behavior mode.
Create mode, how to create an object. This usually includes separating the details of object creation, so that your Code It does not depend on the object type, and you do not need to change the code when adding new types of objects. The modes are:
Abstract Factory: provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.
Builder: separates components of a complex object from its representation, so that different expressions can be created during the same construction process.
Factory method: defines an interface used to create an object, so that the subclass determines which class to instantiate. Factory method delays the instantiation of a class to its subclass.
Prototype: Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object.
Singleton: ensures that a class has only one instance and provides a global access point to it.
Structural Pattern to design objects that meet certain constraints in some projects. Its working principle is as follows: a group of objects are associated with other objects. When the system changes, the relationship between these objects remains unchanged. The modes are:
Adapter: converts an interface of a class to another interface that the customer wants. The adapter mode allows the classes that cannot work together due to incompatibility of interfaces to work together.
Bridge: separates abstract parts from their implementations so that they can all change independently.
Composite: combines objects into a tree structure to represent a "part-whole" hierarchy. Composite makes the customer's use of a single object and composite object consistent.
Decorator: dynamically add some additional responsibilities to an object. In terms of extended functions, the decorator mode is more flexible than the subclass generation method.
Fa C Ade: provides a consistent interface for a group of interfaces in the subsystem. The facade mode defines a high-level interface, which makes the subsystem easier to use.
Flyweight: uses the sharing technology to effectively support a large number of fine-grained objects.
Proxy: provides a proxy for other objects to control access to this object.
Behavior mode refers to Program Objects that process a series of specific types of operations. They encapsulate a series of operations or implement an algorithm. The modes are:
Chain of responsibility (responsibility chain): to cancel the coupling between the request sender and receiver, multiple objects have the opportunity to process the request. Connect these objects into a chain and pass the request along the chain until an object processes it.
Command: encapsulate a request as an object so that you can parameterize the customer with different requests; queue requests or record request logs, and supports cancelable operations.
Interpreter: a language that defines a syntax expression and an interpreter that uses the interpreter to explain sentences in a language.
Interator: provides a method to access each element of an aggregate object sequentially without exposing the internal representation of the object.
Mediator: A mediator object is used to encapsulate a series of object interactions. The intermediary removes the need to explicitly reference each other so that the coupling of the device is loose and the interaction between the objects can be changed independently.
Memento: captures the internal state of an object without compromising encapsulation, and saves the State outside the object. In this way, the object can be restored to the Saved state.
Observer (observer): defines a one-to-many dependency between objects, so that when the state of an object changes, all objects dependent on it are notified and automatically refreshed.
State: allows an object to change its behavior when its internal state changes. The object seems to have modified its class.
Strategy: defines a series of algorithms, encapsulates them one by one, and makes them replaceable. This mode makes the algorithm changes independent of the customers who use it.
Template Method (Template Method): defines the skeleton of an algorithm in an operation, and delays some steps to the subclass. The template method allows the subclass to redefine certain steps of an algorithm without changing the structure of an algorithm.
Visitor: an operation that acts on each element in an object structure. It allows you to define new operations that act on these elements without changing the classes of each element.

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.