Design mode (v) Creator mode (Builder)-Create type

Source: Internet
Author: User

Creator Mode Builder

The creator pattern is to separate the construction of a complex object from its representation, so that the same build process can create different representations, while the client does not have to know the object's build details. You can use the Creator mode when the system needs to create a complex set of objects, and this complex object is more cumbersome to assemble.

Extract all the functional classes from the abstract factory pattern into a single class

Factory class is only responsible for the creation of objects, not responsible for the assembly of objects, through the director class to Assemble,

The abstract factory pattern is similar to the creator pattern, but the creator pattern further implements a single function of the class

Creator mode


How the creator pattern is implemented

The creator pattern is actually an abstract factory-mode evolutionary version.

Abstract Factory mode

Public abstract class FactoryMethod () {protected abstract Translate factorymethodtranslate ();p rotected Abstract Interpret Factorymethodinterpret ();p rotected abstract Speech Factormethodspeech ();p ublic string Saytext (string text) { Translate Translate = Factorymethodtranslate (); Interpret interpret = Factorymethodinterpret (); Speech Speech = Factorymethodspeech (), return Translate.saytext () + "--" + interpret.saytext () + "---" +speech.saytext ();}}

Creator mode

Public abstract class FactoryMethod () {protected abstract Translate factorymethodtranslate ();p rotected Abstract Interpret Factorymethodinterpret ();p rotected abstract Speech Factormethodspeech ();}
public class Director () {private FactoryMethod factorymethod;public FactoryMethod Getfactorymethod () {return factory;} public void Setfactorymethod (FactoryMethod factorymethod) {this.factorymethod = FactoryMethod;} public string Saytext (string text) {Translate Translate = factorymethodtranslate (); Interpret interpret = Factorymethodinterpret (); Speech Speech = Factorymethodspeech (), return Translate.saytext () + "----" + interpret.saytext () + "---" +speech.saytext () ;}}




Design mode (v) Creator mode (Builder)-Create type

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.