Big talk Design Pattern _ builder Pattern

Source: Internet
Author: User

The following is an example of how to draw a person.

Package COM. WZS. design;/*** big talk design mode -- page116 builder mode ** @ author administrator **/public class builderpattern {public static void main (string [] ARGs) {persondirepersonthindire= new persondirector (New personthinbuilder (); // thin personthindire. createperson (); system. out. println (); persondirector personfatdire= new persondirector (New personfatbuilder (); // fat personfatdire. createperson () ;}}/** conductor */class persondirector {private personbuilder; Public persondirector (personbuilder) {This. personbuilder = personbuilder;} // The Creator public void createperson () {personbuilder. buildhead (); personbuilder. buildbody (); personbuilder. buildarm (); personbuilder. buildleg () ;}}/** abstract class */abstract class personbuilder {public abstract void buildhead (); public abstract void buildbody (); public abstract void buildarm (); public abstract void buildleg ();}/** skinny */class personthinbuilder extends personbuilder {@ overridepublic void buildarm () {system. out. println ("thin hand. ") ;}@ overridepublic void buildbody () {system. out. println ("skinny body. ") ;}@ overridepublic void buildhead () {system. out. println ("Thin head. ") ;}@ overridepublic void buildleg () {system. out. println ("skinny leg. ") ;}}/** fat man */class personfatbuilder extends personbuilder {@ overridepublic void buildarm () {system. out. println ("fat man's hand. ") ;}@ overridepublic void buildbody () {system. out. println ("fat body. ") ;}@ overridepublic void buildhead () {system. out. println ("fat head. ") ;}@ overridepublic void buildleg () {system. out. println ("fat legs. ");}}

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.