C # design mode notes

Source: Internet
Author: User

I recently read the C # design mode and made some notes. Here, we also record that the right should be forgotten.

C # design patterns are generally divided into three types: Creation Mode, structure mode, and behavior mode.

 

Creation Mode:Single-piece mode, factory mode, abstract factory mode, generator mode, and prototype mode.

Structure Mode:Adapter mode, bridging mode, composition mode, decoration mode, appearance mode, metadata mode, and proxy mode.

Behavior mode:Intermediary mode, command mode, memorandum mode, state mode, policy mode, interpreter mode, iterator mode, observer mode, visitor mode, template method mode.

 

Category 1:

Singleton pattern ):Ensure that a class has only one instance and provides a global access point to it. For example, cross-form access to the same instance.
Factory pattern ):Select a class instance from a series of related classes based on the data provided to the factory and return it. Example: Oracle and SQL Server Connector class selection
Abstract factory pattern ):Returns a factory for a group of classes.
Builder pattern ):Assemble new objects based on the data and representation provided to them. For example, different controls are displayed based on the user's choice.
Prototype pattern ):From the result to a new result. For example, you can obtain another result based on the SQL query result. Similar to the generator factory, both return classes consisting of objects of many methods.Differences:The abstract factory returns a series of related classes. A generator builds a complex object step by step based on the data provided to it.

 

Category 2:

Adapter pattern ):Convert one class to another.
Bridge pattern ):The class interface is separated from its implementation and does not need to change the caller'sCodeCan replace the implementation process.
Composite pattern ):Combination is the combination of objects. You can build partial-integral relationships or tree relationships of data.
Decorator pattern ):Use a class to wrap a given class to change the behavior of a single object, but you do not need to create a new derived class.
Facde pattern ):A complex system class can be encapsulated into a simple closed interface.
Flyweight pattern ):By sharing (moving parameters externally), the number of individual instances is greatly reduced.
Proxy pattern ):Provides a simple placeholder object for a complex object.

 

Category 3:

Mediator Pattern ):As the only one who understands other classes, the intermediary simplifies the loose modification and maintenance of the communication and promotion sounds. Each control that communicates with the intermediary is called a colleague.
Application: Visual InterfaceProgram.

Command pattern ):Forward requests only to specific objects. Objective: To separate the interface and operation of a program. Disadvantage: added scattered sub-classes

Memento pattern ):Save the data of the object so that it can be restored later. Originator: it is an object and we want to save its status. Memento: another object that stores the state of the initiator. Caretaker: specifies the time for storing the management status, saves the Memorandum, and uses the memorandum to restore the initiator status if necessary.

State pattern ):An object is used to indicate the state of the program and convert the state of the program by converting the object. Previously, different calculations or different contents were executed based on the passed parameters. Switch-case/If else status mode should replace it.

Stractegy pattern ):Similar to the status mode, select a class encapsulated in the context drive as needed.

Observer pattern ):Displays data in multiple forms. In observer mode, data is called a target (subject), and each type of display is called an observer (observer)

Interpreter mode (Interpreter pattern ):Define a syntax for a language and use it to explain the statements in the language.
Applicability:
1. When the reader needs a command interpreter to analyze user commands.
2. When the program needs to analyze an algebraic string.
3. When sending a program to generate various forms of output.

Iterator pattern ):Allows you to access a data list or set in sequence using a standard interface.

Template Method pattern ):First, create a parent class, and leave one or more methods as sub-classes. Is a very simple and common mode. Idea: extract the basic part of a class into a base class without re-appearing in a derived class.

Chain of responsibility ):Multiple classes are allowed to process the same request.
Key points:
1. The chain organization is from the most special to the most general.
2. There is no guarantee that there will be a response under any circumstances.
The responsibility chain is used for analyzer and compiler.

 

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.