Patterns of behavior design for C # Design patterns (behavioral pattern)

Source: Internet
Author: User

Behavioral patterns (behavioral pattern) are abstractions that divide responsibilities and algorithms among different objects. Behavioral patterns are not just about classes and objects, but about the interaction between them.

Behavioral patterns are divided into two types: behavioral patterns of classes and behavior patterns of objects.

The behavior pattern of a class: The behavior pattern of a class uses inheritance relationships to assign behavior in several classes.

The behavior pattern of an object: The behavior pattern of an object uses the aggregation of the object to distribute the behavior.

The behavioral patterns that you will cover later include the following:

Chain of Resp.(责任链模式)A way of passing a request between a chain of objects
Command(命令模式)Encapsulate a command request as an object
Interpreter(解释器模式)A way to include language elements in a program
Iterator(迭代子模式)Sequentially access the elements of a collection
Mediator(中介者模式)Defines simplified communication between classes
Memento(备忘录模式)Capture and restore an object's internal state
Observer(观察者模式)A way of notifying change to a number of classes
State(状态模式)Alter an object's behavior when its state changes
Strategy(策略模式)Encapsulates an algorithm inside a class
Template Method(模版方法模式)Defer the exact steps of an algorithm to a subclass
Visitor(访问者模式)Defines a new operation to a class without change

I. Responsibility chain (Chain of responsibility) mode

The responsibility chain pattern is an object's behavior pattern "GOF95". In the mode of responsibility chain, many objects are connected by each object's reference to their house to form a chain. The request is passed on this chain until an object on the chain decides to process the request. The client issuing the request does not know which object on the chain ultimately handles the request, allowing the system to dynamically rearrange the chain and assign responsibility without affecting the client.

Talking about the flowers from the drums

Drumming is a lively and tense drinking game. In the banquet, the guests sit in order, by a person drumming, drums and the place of the flower is separate, to show just. When the drums started, the bouquets began to pass, the drums fell, and if the bouquet was in someone's hands, the person would have to drink.

It is the application of the chain of responsibility to use drums to spread flowers. The chain of responsibility may be a line, a chain, or part of a tree structure.

Related Article

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.