"Java design mode" "Create mode creational pattern" Construction Mode builder pattern

Source: Internet
Author: User

1  PackageCom.tn.pattern;2 3  Public classClient {4      Public Static voidMain (string[] args) {5Director director=director.getinstance ();6Director.construct (NewConcreteBuilder1 ()); 7Director.construct (NewConcreteBuilder2 ());8     }9 }Ten  One classdirector{ A     StaticDirector director; -     PrivateDirector () {} -      Public StaticDirector getinstance () { the         if(director==NULL) -Director=NewDirector (); -         returnDirector; -     } +      Public voidconstruct (Builder builder) { - Builder.buildpart1 (); + Builder.buildpart2 (); A     } at } -  - Interfacebuilder{ -     voidBuildPart1 (); -     voidBuildPart2 (); - Product Retrieveresult (); in } -  to classConcreteBuilder1Implementsbuilder{ + product product; - @Override the      Public voidBuildPart1 () { *System.out.println ("Concretebuilder1.buildpart1 ()"); $product=NewProduct1 ();Panax Notoginseng     } -      the @Override +      Public voidBuildPart2 () {} A      the @Override +      PublicProduct Retrieveresult () { -         returnproduct; $     } $ } -  - classConcreteBuilder2Implementsbuilder{ the product product; - @OverrideWuyi      Public voidBuildPart1 () {} the      - @Override Wu      Public voidBuildPart2 () { -System.out.println ("Concretebuilder2.buildpart2 ()"); Aboutproduct=NewProduct2 (); $     } -      - @Override -      PublicProduct Retrieveresult () { A         returnproduct; +     } the } -  $ Interfaceproduct{} the  the classProduct1Implementsproduct{ the      PublicProduct1 () { theSystem.out.println ("Product1.product1 ()"); -     } in } the  the classProduct2Implementsproduct{ About      PublicProduct2 () { theSystem.out.println ("Product2.product2 ()"); the     } the}

"Java design mode" "Create mode creational pattern" Construction Mode builder pattern

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.