(Create pattern four) Creator mode

Source: Internet
Author: User

Package com.eyugame.modle;/** * Creator mode * * @author JYC506 * *//* director */public class Director {Ibuilder mybuilder=new Mybuil Der ();p ublic phoneproduct Createmiphone () {Mybuilder.setnameandtype ("millet", "note"); Mybuilder.des ("Price 2300"); return Mybuilder.getphoneproduct ();} Public Phoneproduct Createiphone () {Mybuilder.setnameandtype ("Apple", "6Plus"); Mybuilder.des ("Price 5600"); return Mybuilder.getphoneproduct ();}} /* Create interface */interface ibuilder {void Setnameandtype (string name, string type); void des (string des); Phoneproduct getphoneproduct ();} /* Creator */class Mybuilder implements Ibuilder {phoneproduct phoneproduct = new Phoneproduct (); @Overridepublic void Setnamea Ndtype (string name, String type) {phoneproduct.setname (name);p honeproduct.settype (type);} @Overridepublic void des (String des) {des = Phoneproduct.getname () + phoneproduct.gettype () + des;phoneproduct.setdes ( DES);} @Overridepublic phoneproduct getphoneproduct () {return phoneproduct;}} /* Product */class phoneproduct {private string name;private string tyPe;private String des;public Void Show () {System.out.println (DES);} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public String GetType () {return type;} public void SetType (String type) {this.type = type;} Public String Getdes () {return des;} public void Setdes (String des) {this.des = des;}} Class Testbuilder{public static void Main (string[] args) {Director Director=new Director (); Phoneproduct Xiaomi=director.createmiphone (); Xiaomi.show (); Phoneproduct Iphone=director.createiphone (); Iphone.show ();}}


(Create pattern four) Creator mode

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.