Learning design patterns (C #)

  Outside of work spent half a year studying the "Head First Design Patterns" book, regarded as a beginning, in this brief summary revision.

 First, the mode

1.Strategy strategy pattern

Define a series of algorithms, encapsulate them one by one, so that they can replace each other.

Personal understanding: use delegates to achieve, such as lamda expressions.

2.Observe observer

Definition of the dependencies between the subject an-many, so that when a state of the object changes, and it is all dependent objects are notified automatically refreshed.

Personal understanding: common mode, such as C # events

3.Decorator decorator

Dynamically add additional responsibilities to an object

Personal understanding: a group of the same object inherits from the abstract class or interface, an object by a solid column of another object for initialization, to achieve additional responsibilities. That nested initialization

4.Factory Method Factory Pattern

Define an interface for creating an object, but let subclasses decide which class to instantiate.

Personal understanding: the instance of the class are on the factory class, subclass instantiating the factory class to create instances of other subclasses, mutual decoupling between the various subclasses.

5.Abstract Factory Abstract Factory

Create a series of related or dependent objects interface with each other, without specifying its type

Personal understanding: abstract factory is an interface, the interface is a series of parent plants subclass, using the factory method in the abstract factory be achieved.

6.Singleton singleton

To ensure that a class has only one real column, and provide a global access point to access it

Personal understanding: common, focusing on how to ensure the guarantee singleton in a multithreaded competition

7.Command command

It encapsulates a request for an object, thus making your clients using different parameterization of the request; the request queue or log requests, and support the operation of the cancel.

Personal understanding:

8.Adapter adapter

Converting the interface of a class clients expect another interface.

Personal understanding: In order to be compatible interfaces. Want to as Aa () is converted into B (), a new adapter is usually defined object B, the object A is created in the original instance of adapter object B, and then implement the call Aa () of Bb.

9.Facade appearance

A set of interfaces to provide a consistent interface subsystem, defines a high-level interface that makes the subsystem easier to use.

Personal understanding: the definition of a high-level interface, call some interface subsystem of the interface, the realization of integration.

10.Template Template Method

The algorithm defines a skeleton of the operation, some steps to subclasses delay.

Personal understanding: virtual methods in C # and rewrite

Hook: declare methods in an abstract class, but only the realization of space or the default implementation.

Gouzi allows subclasses has the ability to be linked to different points of the algorithm

11.Iterator iterator

There is provided a method of sequential access to each element of a polymeric object, but does not require the internal representation of the object is exposed.

Personal understanding: a generic interface to traverse. As IEnumerable, IEnumerator

12.Composite combined mode

Combining objects in a tree structure to represent "part - whole" hierarchy.

Personal appreciated: Object model defined by a combination of process objects by recursively to the individual objects and composite objects consistent treatment.

13.State state mode

Allowing the object to change its behavior when its internal state changes.

Personal understanding: that the object uses a state of the interface to represent the state of the object, different states subclass inherits this interface and achieve the object state changes.

Note: No other mode of understanding

14.Proxy agent

Providing a proxy to control access to the object to other objects.

Personal understanding:

 15.Bridge bridge

The abstraction from its implementation so that they can vary independently

16.Builder generator

It represents the construct and its separation of a complex object, such that the same build process can create different representations

17.Chain of Responsibility Chain of Responsibility

Coupled between the sender and receiver of the request to release, the plurality of object a chance to handle the request. These objects together into a chain, and pass the request along the chain until an object handles it.

Personal understanding: There are multiple recipients accept the request queue

18.Flyweight flies amount

The use of object sharing technology technology to effectively support large numbers of fine-grained

Personal understanding:

19.Interpreter interpreter

Given a language, which defines a grammar representation and define an interpreter, the interpreter uses the representation to interpret sentences in the language.

20.Mediator Mediator

Use a mediation object that encapsulates set of objects interact. Mediator keeping objects refer to each of the display, thereby decoupling it loose, and can be changed independently of the interaction between them.

21.Memento memorandum

Without violating encapsulation, capture and the internal state of an object, and save the state outside the object. So that later you can return the object to the saved state.

Personal understanding: Archive and Restore

22.Prototype prototype

You specify the type of object prototype created instance, and to create new objects by copying this prototype.

23.Visitor visitors

It represents an operation of each element of an object structure effect. It is something you can not change the definition of the class action under the premise of each element in the operation of these new elements.

 

Guess you like

Origin www.cnblogs.com/dengquan/p/12160685.html