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