Summary of design patterns-Comparison of Models

Source: Internet
Author: User

1. abstractfactoryVSBuilder

The Builder mode is very similar to the Abstract Factory mode in Abstract view. However, the Builder mode focuses on how to assemble an object, while the abstract factory focuses on which class of the instance. In the Builder mode, the algorithm of the constructed object is abstracted into the Controller ctor of the object. Director is responsible for instance objects step by step according to the construction algorithm. The controller Director of the object does not have to implement a fixed interface. The client is not responsible for the instance of the object. The controller ctor of the object in Builder mode determines the components of the Instance Object.
The Builder and Abstract Factory patterns are similar in that they both look at construction at an abstract level. however, the Builder pattern is concerned with how a single object is made up by the different factories, whereas the Abstract Factory pattern is concerned with what products are made. the Builder pattern matching acts the algorithm for construction by including the concept of a ctor. the director is responsible for itemizing the steps and callon builders to fulfill them. directors do not have to conform to an interface.

2. Chain of ResponsibilityVSCommand

The responsibility chain mode and command mode both decouple the sender and receiver, which enhances the level and reusability of the system. The responsibility chain mode decouples requests transmitted by possible receivers, while the command mode encapsulates requests as objects.

A similarity between the Chain of Responsibility and the Command patterns is that they decouple senders and receivers, thus improving the layering and reusability of a system. the Chain of Responsibility pattern supports decoupling by passing a request between potential receivers, whereas the Command pattern supports using a command object to encapsulate a request.

3. StrategyVSStateVSTemplateMethod

Policy object encapsulation algorithm. A State object encapsulates the behavior or state transition in a certain state.

Both modes use polymorphism, define the parent interface or abstract class, and implement a series of subclasses of the method. Both modes use context to maintain or determine the state transition. The biggest difference is that the algorithm is encapsulated into the policy mode, while the encapsulation status is in the state mode. The template method mode and Policy mode are very similar Based on algorithms. Unlike the rule mode template method, some of the steps in the algorithm are pushed to the subclass.

There are considerable similarities between the Strategy and State patterns, but the main difference is one of intent:
• A Strategy object encapsulates an algorithm
• A State object encapsulates a state-dependent behavior (and possibly state transitions)
Both patterns are concerned with polymorphism. both patterns define a parent interface or abstract class and a series of subclasses that implement the methods therein. and both patterns have a context that they maintain and use to decide on state transitions. so, the biggest difference between the patterns is that we encapsulate an algorithm into strategy classes in the Strategy pattern, but we encapsulate state into state classes in the state pattern.

The template method pattern is more like the strategy pattern in that it is algorithm based. The steps of the algorithm are specified in the template method and some are deferred to domain classes.
 

 

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.