- Statybininko dizaino modelis
- Builder DP privalumas
- Builder DP naudojimas
- Builder DP UML
- Builder DP pavyzdys
„Builder Pattern“ tai sako „Sukurti sudėtingą objektą iš paprastų objektų, naudojant žingsnis po žingsnio metodą“
Jis dažniausiai naudojamas, kai objekto negalima sukurti vienu žingsniu, pavyzdžiui, išjungiant sudėtingą objektą.
„Builder“ dizaino modelio pranašumas
Pagrindiniai „Builder Pattern“ pranašumai yra šie:
- Tai aiškiai atskiria objekto konstrukciją ir vaizdavimą.
- Tai leidžia geriau kontroliuoti statybos procesą.
- Tai padeda pakeisti vidinį objektų vaizdavimą.
UML Builder modelio pavyzdys
Builder dizaino modelio pavyzdys
Norėdami sukurti paprastą statybininko dizaino modelio pavyzdį, turite atlikti 6 toliau nurodytus veiksmus.
išaukštinimas
- Sukurkite pakavimo sąsają
- Sukurkite 2 abstrakčių klasių kompaktinį diską ir įmonę
- Sukurkite 2 įmonės diegimo klases: Sony ir Samsung
- Sukurkite CDType klasę
- Sukurkite CDBuilder klasę
- Sukurkite „BuilderDemo“ klasę
1) Sukurkite pakavimo sąsają
Failas: Packing.javapublic interface Packing { public String pack(); public int price(); }
2) Sukurti 2 abstrakčias klases CD ir Įmonė
Sukurkite abstrakčiosios klasės kompaktinį diską, kuriame bus įdiegta pakavimo sąsaja.
Failas: CD.javapublic abstract class CD implements Packing{ public abstract String pack(); }Failas: Company.java
public abstract class Company extends CD{ public abstract int price(); }
3) Sukurkite 2 įmonės diegimo klases: Sony ir Samsung
Failas: Sony.javapublic class Sony extends Company{ @Override public int price(){ return 20; } @Override public String pack(){ return 'Sony CD'; } }//End of the Sony class.Failas: Samsung.java
public class Samsung extends Company { @Override public int price(){ return 15; } @Override public String pack(){ return 'Samsung CD'; } }//End of the Samsung class.
4) Sukurkite CDType klasę
Failas: CDType.javaimport java.util.ArrayList; import java.util.List; public class CDType { private List items=new ArrayList(); public void addItem(Packing packs) { items.add(packs); } public void getCost(){ for (Packing packs : items) { packs.price(); } } public void showItems(){ for (Packing packing : items){ System.out.print('CD name : '+packing.pack()); System.out.println(', Price : '+packing.price()); } } }//End of the CDType class.
5) Sukurkite CDBuilder klasę
Failas: CDBuilder.javapublic class CDBuilder { public CDType buildSonyCD(){ CDType cds=new CDType(); cds.addItem(new Sony()); return cds; } public CDType buildSamsungCD(){ CDType cds=new CDType(); cds.addItem(new Samsung()); return cds; } }// End of the CDBuilder class.
6) Sukurkite BuilderDemo klasę
Failas: BuilderDemo.javapublic class BuilderDemo{ public static void main(String args[]){ CDBuilder cdBuilder=new CDBuilder(); CDType cdType1=cdBuilder.buildSonyCD(); cdType1.showItems(); CDType cdType2=cdBuilder.buildSamsungCD(); cdType2.showItems(); } }
atsisiųskite šį kūrimo modelio pavyzdį
Aukščiau pateikto pavyzdžio išvestis
CD name : Sony CD, Price : 20 CD name : Samsung CD, Price : 15
Kitas realaus pasaulio „Builder Pattern“ pavyzdys
UML kūrėjo modeliui:
Mes svarstome verslo atvejį pica-namelis kur galime įsigyti įvairių rūšių picų ir šaltų gėrimų.
pica gali būti kelių rūšių daržovių pica arba ne daržovių pica (pvz., sūrio pica, svogūnų pica, masala-pica ir tt) ir bus 4 dydžių, t. y. maža, vidutinė, didelė, ypač didelė.
jvm java
Saltas gerimas gali būti kelių tipų (pvz., Pepsi, Coke, Dew, Sprite, Fanta, Maaza, Limca, Thums-up ir kt.) ir bus 3 dydžių mažas, vidutinis, didelis.
Realaus pasaulio statybininko modelio pavyzdys
Pažiūrėkime žingsnis po žingsnio realaus pasaulio statybininko dizaino modelio pavyzdį.
1 žingsnis: Sukurkite sąsajos elementą, vaizduojantį picą ir šaltą gėrimą.
Failas: Item.javapublic interface Item { public String name(); public String size(); public float price(); }// End of the interface Item.
2 žingsnis: Sukurkite abstrakčią klasę Pica, kuri bus pritaikyta sąsajos elementui.
Belfordo algoritmasFailas: Pizza.java
public abstract class Pizza implements Item{ @Override public abstract float price(); }
3 veiksmas: Sukurkite abstrakčią klasę „ColdDrink“, kuri bus pritaikyta sąsajos elementui.
Failas: ColdDrink.javapublic abstract class ColdDrink implements Item{ @Override public abstract float price(); }
4 veiksmas: Sukurkite abstrakčią klasę „VegPizza“, kuri bus išplėsta iki abstrakčios klasės „Pica“.
Failas: VegPizza.javapublic abstract class VegPizza extends Pizza{ @Override public abstract float price(); @Override public abstract String name(); @Override public abstract String size(); }// End of the abstract class VegPizza.
5 veiksmas: Sukurkite abstrakčią klasę NonVegPizza, kuri bus išplėsta iki abstrakčios klasės Pica.
Failas: NonVegPizza.javapublic abstract class NonVegPizza extends Pizza{ @Override public abstract float price(); @Override public abstract String name(); @Override public abstract String size(); }// End of the abstract class NonVegPizza.
6 veiksmas: Dabar sukurkite konkrečius poklasius SmallCheezePizza, MediumCheezePizza, LargeCheezePizza, ExtraLargeCheezePizza, kurie apims abstrakčią klasę VegPizza.
Failas: SmallCheezePizza.javapublic class SmallCheezePizza extends VegPizza{ @Override public float price() { return 170.0f; } @Override public String name() { return 'Cheeze Pizza'; } @Override public String size() { return 'Small size'; } }// End of the SmallCheezePizza class.Failas: MediumCheezePizza.java
public class MediumCheezePizza extends VegPizza{ @Override public float price() { return 220.f; } @Override public String name() { return 'Cheeze Pizza'; } @Override public String size() { return 'Medium Size'; } }// End of the MediumCheezePizza class. File: LargeCheezePizza.java <pre> public class LargeCheezePizza extends VegPizza{ @Override public float price() { return 260.0f; } @Override public String name() { return 'Cheeze Pizza'; } @Override public String size() { return 'Large Size'; } }// End of the LargeCheezePizza class. </pre> File: ExtraLargeCheezePizza.java <pre> public class ExtraLargeCheezePizza extends VegPizza{ @Override public float price() { return 300.f; } @Override public String name() { return 'Cheeze Pizza'; } @Override public String size() { return 'Extra-Large Size'; } }// End of the ExtraLargeCheezePizza class. </pre> <p>Step 7: <b>Now, similarly create concrete sub-classes SmallOnionPizza, MediumOnionPizza, LargeOnionPizza, ExtraLargeOnionPizza that will extend to the abstract class VegPizza.</b> </p> File: SmallOnionPizza.java <pre> public class SmallOnionPizza extends VegPizza { @Override public float price() { return 120.0f; } @Override public String name() { return 'Onion Pizza'; } @Override public String size() { return 'Small Size'; } }// End of the SmallOnionPizza class. </pre> File: MediumOnionPizza.java <pre> public class MediumOnionPizza extends VegPizza { @Override public float price() { return 150.0f; } @Override public String name() { return 'Onion Pizza'; } @Override public String size() { return 'Medium Size'; } }// End of the MediumOnionPizza class. </pre> File: LargeOnionPizza.java <pre> public class LargeOnionPizza extends VegPizza{ @Override public float price() { return 180.0f; } @Override public String name() { return 'Onion Pizza'; } @Override public String size() { return 'Large size'; } }// End of the LargeOnionPizza class. </pre> File: ExtraLargeOnionPizza.java <pre> public class ExtraLargeOnionPizza extends VegPizza { @Override public float price() { return 200.0f; } @Override public String name() { return 'Onion Pizza'; } @Override public String size() { return 'Extra-Large Size'; } }// End of the ExtraLargeOnionPizza class </pre> <p>Step 8: <b>Now, similarly create concrete sub-classes SmallMasalaPizza, MediumMasalaPizza, LargeMasalaPizza, ExtraLargeMasalaPizza that will extend to the abstract class VegPizza.</b> </p> File: SmallMasalaPizza.java <pre> public class SmallMasalaPizza extends VegPizza{ @Override public float price() { return 100.0f; } @Override public String name() { return 'Masala Pizza'; } @Override public String size() { return 'Samll Size'; } }// End of the SmallMasalaPizza class </pre> File: MediumMasalaPizza.java <pre> public class MediumMasalaPizza extends VegPizza { @Override public float price() { return 120.0f; } @Override public String name() { return 'Masala Pizza'; } @Override public String size() { return 'Medium Size'; } </pre> File: LargeMasalaPizza.java <pre> public class LargeMasalaPizza extends VegPizza{ @Override public float price() { return 150.0f; } @Override public String name() { return 'Masala Pizza'; } @Override public String size() { return 'Large Size'; } } //End of the LargeMasalaPizza class </pre> File: ExtraLargeMasalaPizza.java <pre> public class ExtraLargeMasalaPizza extends VegPizza { @Override public float price() { return 180.0f; } @Override public String name() { return 'Masala Pizza'; } @Override public String size() { return 'Extra-Large Size'; } }// End of the ExtraLargeMasalaPizza class </pre> <p>Step 9: <b>Now, create concrete sub-classes SmallNonVegPizza, MediumNonVegPizza, LargeNonVegPizza, ExtraLargeNonVegPizza that will extend to the abstract class NonVegPizza.</b> </p> File: SmallNonVegPizza.java <pre> public class SmallNonVegPizza extends NonVegPizza { @Override public float price() { return 180.0f; } @Override public String name() { return 'Non-Veg Pizza'; } @Override public String size() { return 'Samll Size'; } }// End of the SmallNonVegPizza class </pre> File: MediumNonVegPizza.java <pre> public class MediumNonVegPizza extends NonVegPizza{ @Override public float price() { return 200.0f; } @Override public String name() { return 'Non-Veg Pizza'; } @Override public String size() { return 'Medium Size'; } </pre> File: LargeNonVegPizza.java <pre> public class LargeNonVegPizza extends NonVegPizza{ @Override public float price() { return 220.0f; } @Override public String name() { return 'Non-Veg Pizza'; } @Override public String size() { return 'Large Size'; } }// End of the LargeNonVegPizza class </pre> File: ExtraLargeNonVegPizza.java <pre> public class ExtraLargeNonVegPizza extends NonVegPizza { @Override public float price() { return 250.0f; } @Override public String name() { return 'Non-Veg Pizza'; } @Override public String size() { return 'Extra-Large Size'; } } // End of the ExtraLargeNonVegPizza class </pre> <p>Step 10: <b>Now, create two abstract classes Pepsi and Coke that will extend abstract class ColdDrink. </b> </p> File: Pepsi.java <pre> public abstract class Pepsi extends ColdDrink { @Override public abstract String name(); @Override public abstract String size(); @Override public abstract float price(); }// End of the Pepsi class </pre> File: Coke.java <pre> public abstract class Coke extends ColdDrink { @Override public abstract String name(); @Override public abstract String size(); @Override public abstract float price(); }// End of the Coke class <p>Step 11: <b>Now, create concrete sub-classes SmallPepsi, MediumPepsi, LargePepsi that will extend to the abstract class Pepsi.</b> </p> File: SmallPepsi.java <pre> public class SmallPepsi extends Pepsi{ @Override public String name() { return '300 ml Pepsi'; } @Override public float price() { return 25.0f; } @Override public String size() { return 'Small Size'; } }// End of the SmallPepsi class </pre> File: MediumPepsi.java <pre> public class MediumPepsi extends Pepsi { @Override public String name() { return '500 ml Pepsi'; } @Override public String size() { return 'Medium Size'; } @Override public float price() { return 35.0f; } }// End of the MediumPepsi class </pre> File: LargePepsi.java <pre> public class LargePepsi extends Pepsi{ @Override public String name() { return '750 ml Pepsi'; } @Override public String size() { return 'Large Size'; } @Override public float price() { return 50.0f; } }// End of the LargePepsi class </pre> <p>Step 12: <b>Now, create concrete sub-classes SmallCoke, MediumCoke, LargeCoke that will extend to the abstract class Coke.</b> </p> File: SmallCoke.java <pre> public class SmallCoke extends Coke{ @Override public String name() { return '300 ml Coke'; } @Override public String size() { return 'Small Size'; } @Override public float price() { return 25.0f; } }// End of the SmallCoke class </pre> File: MediumCoke.java <pre> public class MediumCoke extends Coke{ @Override public String name() { return '500 ml Coke'; } @Override public String size() { return 'Medium Size'; } @Override public float price() { return 35.0f; } }// End of the MediumCoke class </pre> File: LargeCoke.java <pre> public class LargeCoke extends Coke { @Override public String name() { return '750 ml Coke'; } @Override public String size() { return 'Large Size'; } @Override public float price() { return 50.0f; } }// End of the LargeCoke class <p>Step 13: <b>Create an OrderedItems class that are having Item objects defined above.</b> </p> File: OrderedItems.java <pre> import java.util.ArrayList; import java.util.List; public class OrderedItems { List items=new ArrayList(); public void addItems(Item item){ items.add(item); } public float getCost(){ float cost=0.0f; for (Item item : items) { cost+=item.price(); } return cost; } public void showItems(){ for (Item item : items) { System.out.println('Item is:' +item.name()); System.out.println('Size is:' +item.size()); System.out.println('Price is: ' +item.price()); } } }// End of the OrderedItems class </pre> <p>Step 14: <b>Create an OrderBuilder class that will be responsible to create the objects of OrderedItems class.</b> </p> File: OrdereBuilder.java <pre> import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class OrderBuilder { public OrderedItems preparePizza() throws IOException{ OrderedItems itemsOrder=new OrderedItems(); BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); System.out.println(' Enter the choice of Pizza '); System.out.println('============================'); System.out.println(' 1. Veg-Pizza '); System.out.println(' 2. Non-Veg Pizza '); System.out.println(' 3. Exit '); System.out.println('============================'); int pizzaandcolddrinkchoice=Integer.parseInt(br.readLine()); switch(pizzaandcolddrinkchoice) { case 1:{ System.out.println('You ordered Veg Pizza'); System.out.println(' '); System.out.println(' Enter the types of Veg-Pizza '); System.out.println('------------------------------'); System.out.println(' 1.Cheeze Pizza '); System.out.println(' 2.Onion Pizza '); System.out.println(' 3.Masala Pizza '); System.out.println(' 4.Exit '); System.out.println('------------------------------'); int vegpizzachoice=Integer.parseInt(br.readLine()); switch(vegpizzachoice) { case 1: { System.out.println('You ordered Cheeze Pizza'); System.out.println('Enter the cheeze pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Cheeze Pizza '); System.out.println(' 2. Medium Cheeze Pizza '); System.out.println(' 3. Large Cheeze Pizza '); System.out.println(' 4. Extra-Large Cheeze Pizza '); System.out.println('------------------------------------'); int cheezepizzasize=Integer.parseInt(br.readLine()); switch(cheezepizzasize) { case 1: itemsOrder.addItems(new SmallCheezePizza()); break; case 2: itemsOrder.addItems(new MediumCheezePizza()); break; case 3: itemsOrder.addItems(new LargeCheezePizza()); break; case 4: itemsOrder.addItems(new ExtraLargeCheezePizza()); break; case 2: { System.out.println('You ordered Onion Pizza'); System.out.println('Enter the Onion pizza size'); System.out.println('----------------------------------'); System.out.println(' 1. Small Onion Pizza '); System.out.println(' 2. Medium Onion Pizza '); System.out.println(' 3. Large Onion Pizza '); System.out.println(' 4. Extra-Large Onion Pizza '); System.out.println('----------------------------------'); int onionpizzasize=Integer.parseInt(br.readLine()); switch(onionpizzasize) { case 1: itemsOrder.addItems(new SmallOnionPizza()); break; case 2: itemsOrder.addItems(new MediumOnionPizza()); break; case 3: itemsOrder.addItems(new LargeOnionPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeOnionPizza()); break; } } break; case 3: { System.out.println('You ordered Masala Pizza'); System.out.println('Enter the Masala pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Masala Pizza '); System.out.println(' 2. Medium Masala Pizza '); System.out.println(' 3. Large Masala Pizza '); System.out.println(' 4. Extra-Large Masala Pizza '); System.out.println('------------------------------------'); int masalapizzasize=Integer.parseInt(br.readLine()); switch(masalapizzasize) { case 1: itemsOrder.addItems(new SmallMasalaPizza()); break; case 2: itemsOrder.addItems(new MediumMasalaPizza()); break; case 3: itemsOrder.addItems(new LargeMasalaPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeMasalaPizza()); break; } } break; } } break;// Veg- pizza choice completed. case 2: { System.out.println('You ordered Non-Veg Pizza'); System.out.println(' '); System.out.println('Enter the Non-Veg pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Non-Veg Pizza '); System.out.println(' 2. Medium Non-Veg Pizza '); System.out.println(' 3. Large Non-Veg Pizza '); System.out.println(' 4. Extra-Large Non-Veg Pizza '); System.out.println('------------------------------------'); int nonvegpizzasize=Integer.parseInt(br.readLine()); switch(nonvegpizzasize) { case 1: itemsOrder.addItems(new SmallNonVegPizza()); break; case 2: itemsOrder.addItems(new MediumNonVegPizza()); break; case 3: itemsOrder.addItems(new LargeNonVegPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeNonVegPizza()); break; } } break; default: { break; } }//end of main Switch //continued?.. System.out.println(' Enter the choice of ColdDrink '); System.out.println('============================'); System.out.println(' 1. Pepsi '); System.out.println(' 2. Coke '); System.out.println(' 3. Exit '); System.out.println('============================'); int coldDrink=Integer.parseInt(br.readLine()); switch (coldDrink) { case 1: { System.out.println('You ordered Pepsi '); System.out.println('Enter the Pepsi Size '); System.out.println('------------------------'); System.out.println(' 1. Small Pepsi '); System.out.println(' 2. Medium Pepsi '); System.out.println(' 3. Large Pepsi '); System.out.println('------------------------'); int pepsisize=Integer.parseInt(br.readLine()); switch(pepsisize) { case 1: itemsOrder.addItems(new SmallPepsi()); break; case 2: itemsOrder.addItems(new MediumPepsi()); break; case 3: itemsOrder.addItems(new LargePepsi()); break; } } break; case 2: { System.out.println('You ordered Coke'); System.out.println('Enter the Coke Size'); System.out.println('------------------------'); System.out.println(' 1. Small Coke '); System.out.println(' 2. Medium Coke '); System.out.println(' 3. Large Coke '); System.out.println(' 4. Extra-Large Coke '); System.out.println('------------------------'); int cokesize=Integer.parseInt(br.readLine()); switch(cokesize) { case 1: itemsOrder.addItems(new SmallCoke()); break; case 2: itemsOrder.addItems(new MediumCoke()); break; case 3: itemsOrder.addItems(new LargeCoke()); break; } } break; default: { break; } }//End of the Cold-Drink switch return itemsOrder; } //End of the preparePizza() method </pre> <p>Step 15: <b>Create a BuilderDemo class that will use the OrderBuilder class.</b> </p> File: Prototype.java <pre> import java.io.IOException; public class BuilderDemo { public static void main(String[] args) throws IOException { // TODO code application logic here OrderBuilder builder=new OrderBuilder(); OrderedItems orderedItems=builder.preparePizza(); orderedItems.showItems(); System.out.println(' '); System.out.println('Total Cost : '+ orderedItems.getCost()); } }// End of the BuilderDemo class </pre> <hr> download this Builder Pattern Example <h4>Output</h4> </pre></pre>Failas: ExtraLargeCheezePizza.java
public class ExtraLargeCheezePizza extends VegPizza{ @Override public float price() { return 300.f; } @Override public String name() { return 'Cheeze Pizza'; } @Override public String size() { return 'Extra-Large Size'; } }// End of the ExtraLargeCheezePizza class.
7 veiksmas: Dabar panašiai sukurkite konkrečius poklasius SmallOnionPizza, MediumOnionPizza, LargeOnionPizza, ExtraLargeOnionPizza, kurie apims abstrakčią klasę VegPizza.
Failas: SmallOnionPizza.javapublic class SmallOnionPizza extends VegPizza { @Override public float price() { return 120.0f; } @Override public String name() { return 'Onion Pizza'; } @Override public String size() { return 'Small Size'; } }// End of the SmallOnionPizza class.Failas: MediumOnionPizza.java
public class MediumOnionPizza extends VegPizza { @Override public float price() { return 150.0f; } @Override public String name() { return 'Onion Pizza'; } @Override public String size() { return 'Medium Size'; } }// End of the MediumOnionPizza class.Failas: LargeOnionPizza.java
public class LargeOnionPizza extends VegPizza{ @Override public float price() { return 180.0f; } @Override public String name() { return 'Onion Pizza'; } @Override public String size() { return 'Large size'; } }// End of the LargeOnionPizza class.Failas: ExtraLargeOnionPizza.java
public class ExtraLargeOnionPizza extends VegPizza { @Override public float price() { return 200.0f; } @Override public String name() { return 'Onion Pizza'; } @Override public String size() { return 'Extra-Large Size'; } }// End of the ExtraLargeOnionPizza class
8 veiksmas: Dabar panašiai sukurkite konkrečius poklasius SmallMasalaPizza, MediumMasalaPizza, LargeMasalaPizza, ExtraLargeMasalaPizza, kurie apims abstrakčią klasę VegPizza.
Failas: SmallMasalaPizza.javapublic class SmallMasalaPizza extends VegPizza{ @Override public float price() { return 100.0f; } @Override public String name() { return 'Masala Pizza'; } @Override public String size() { return 'Samll Size'; } }// End of the SmallMasalaPizza classFailas: MediumMasalaPizza.java
public class MediumMasalaPizza extends VegPizza { @Override public float price() { return 120.0f; } @Override public String name() { return 'Masala Pizza'; } @Override public String size() { return 'Medium Size'; }Failas: LargeMasalaPizza.java
public class LargeMasalaPizza extends VegPizza{ @Override public float price() { return 150.0f; } @Override public String name() { return 'Masala Pizza'; } @Override public String size() { return 'Large Size'; } } //End of the LargeMasalaPizza classFailas: ExtraLargeMasalaPizza.java
public class ExtraLargeMasalaPizza extends VegPizza { @Override public float price() { return 180.0f; } @Override public String name() { return 'Masala Pizza'; } @Override public String size() { return 'Extra-Large Size'; } }// End of the ExtraLargeMasalaPizza class
9 veiksmas: Dabar sukurkite konkrečius poklasius SmallNonVegPizza, MediumNonVegPizza, LargeNonVegPizza, ExtraLargeNonVegPizza, kurie apims abstrakčią klasę NonVegPizza.
Failas: SmallNonVegPizza.javapublic class SmallNonVegPizza extends NonVegPizza { @Override public float price() { return 180.0f; } @Override public String name() { return 'Non-Veg Pizza'; } @Override public String size() { return 'Samll Size'; } }// End of the SmallNonVegPizza classFailas: MediumNonVegPizza.java
public class MediumNonVegPizza extends NonVegPizza{ @Override public float price() { return 200.0f; } @Override public String name() { return 'Non-Veg Pizza'; } @Override public String size() { return 'Medium Size'; }Failas: LargeNonVegPizza.java
public class LargeNonVegPizza extends NonVegPizza{ @Override public float price() { return 220.0f; } @Override public String name() { return 'Non-Veg Pizza'; } @Override public String size() { return 'Large Size'; } }// End of the LargeNonVegPizza classFailas: ExtraLargeNonVegPizza.java
public class ExtraLargeNonVegPizza extends NonVegPizza { @Override public float price() { return 250.0f; } @Override public String name() { return 'Non-Veg Pizza'; } @Override public String size() { return 'Extra-Large Size'; } } // End of the ExtraLargeNonVegPizza class
10 veiksmas: Dabar sukurkite dvi abstrakčias klases „Pepsi“ ir „Coke“, kurios išplės abstrakčiąją „ColdDrink“ klasę.
Failas: Pepsi.javapublic abstract class Pepsi extends ColdDrink { @Override public abstract String name(); @Override public abstract String size(); @Override public abstract float price(); }// End of the Pepsi classFailas: Coke.java
public abstract class Coke extends ColdDrink { @Override public abstract String name(); @Override public abstract String size(); @Override public abstract float price(); }// End of the Coke class <p>Step 11: <b>Now, create concrete sub-classes SmallPepsi, MediumPepsi, LargePepsi that will extend to the abstract class Pepsi.</b> </p> File: SmallPepsi.java <pre> public class SmallPepsi extends Pepsi{ @Override public String name() { return '300 ml Pepsi'; } @Override public float price() { return 25.0f; } @Override public String size() { return 'Small Size'; } }// End of the SmallPepsi class </pre> File: MediumPepsi.java <pre> public class MediumPepsi extends Pepsi { @Override public String name() { return '500 ml Pepsi'; } @Override public String size() { return 'Medium Size'; } @Override public float price() { return 35.0f; } }// End of the MediumPepsi class </pre> File: LargePepsi.java <pre> public class LargePepsi extends Pepsi{ @Override public String name() { return '750 ml Pepsi'; } @Override public String size() { return 'Large Size'; } @Override public float price() { return 50.0f; } }// End of the LargePepsi class </pre> <p>Step 12: <b>Now, create concrete sub-classes SmallCoke, MediumCoke, LargeCoke that will extend to the abstract class Coke.</b> </p> File: SmallCoke.java <pre> public class SmallCoke extends Coke{ @Override public String name() { return '300 ml Coke'; } @Override public String size() { return 'Small Size'; } @Override public float price() { return 25.0f; } }// End of the SmallCoke class </pre> File: MediumCoke.java <pre> public class MediumCoke extends Coke{ @Override public String name() { return '500 ml Coke'; } @Override public String size() { return 'Medium Size'; } @Override public float price() { return 35.0f; } }// End of the MediumCoke class </pre> File: LargeCoke.java <pre> public class LargeCoke extends Coke { @Override public String name() { return '750 ml Coke'; } @Override public String size() { return 'Large Size'; } @Override public float price() { return 50.0f; } }// End of the LargeCoke class <p>Step 13: <b>Create an OrderedItems class that are having Item objects defined above.</b> </p> File: OrderedItems.java <pre> import java.util.ArrayList; import java.util.List; public class OrderedItems { List items=new ArrayList(); public void addItems(Item item){ items.add(item); } public float getCost(){ float cost=0.0f; for (Item item : items) { cost+=item.price(); } return cost; } public void showItems(){ for (Item item : items) { System.out.println('Item is:' +item.name()); System.out.println('Size is:' +item.size()); System.out.println('Price is: ' +item.price()); } } }// End of the OrderedItems class </pre> <p>Step 14: <b>Create an OrderBuilder class that will be responsible to create the objects of OrderedItems class.</b> </p> File: OrdereBuilder.java <pre> import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class OrderBuilder { public OrderedItems preparePizza() throws IOException{ OrderedItems itemsOrder=new OrderedItems(); BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); System.out.println(' Enter the choice of Pizza '); System.out.println('============================'); System.out.println(' 1. Veg-Pizza '); System.out.println(' 2. Non-Veg Pizza '); System.out.println(' 3. Exit '); System.out.println('============================'); int pizzaandcolddrinkchoice=Integer.parseInt(br.readLine()); switch(pizzaandcolddrinkchoice) { case 1:{ System.out.println('You ordered Veg Pizza'); System.out.println(' '); System.out.println(' Enter the types of Veg-Pizza '); System.out.println('------------------------------'); System.out.println(' 1.Cheeze Pizza '); System.out.println(' 2.Onion Pizza '); System.out.println(' 3.Masala Pizza '); System.out.println(' 4.Exit '); System.out.println('------------------------------'); int vegpizzachoice=Integer.parseInt(br.readLine()); switch(vegpizzachoice) { case 1: { System.out.println('You ordered Cheeze Pizza'); System.out.println('Enter the cheeze pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Cheeze Pizza '); System.out.println(' 2. Medium Cheeze Pizza '); System.out.println(' 3. Large Cheeze Pizza '); System.out.println(' 4. Extra-Large Cheeze Pizza '); System.out.println('------------------------------------'); int cheezepizzasize=Integer.parseInt(br.readLine()); switch(cheezepizzasize) { case 1: itemsOrder.addItems(new SmallCheezePizza()); break; case 2: itemsOrder.addItems(new MediumCheezePizza()); break; case 3: itemsOrder.addItems(new LargeCheezePizza()); break; case 4: itemsOrder.addItems(new ExtraLargeCheezePizza()); break; case 2: { System.out.println('You ordered Onion Pizza'); System.out.println('Enter the Onion pizza size'); System.out.println('----------------------------------'); System.out.println(' 1. Small Onion Pizza '); System.out.println(' 2. Medium Onion Pizza '); System.out.println(' 3. Large Onion Pizza '); System.out.println(' 4. Extra-Large Onion Pizza '); System.out.println('----------------------------------'); int onionpizzasize=Integer.parseInt(br.readLine()); switch(onionpizzasize) { case 1: itemsOrder.addItems(new SmallOnionPizza()); break; case 2: itemsOrder.addItems(new MediumOnionPizza()); break; case 3: itemsOrder.addItems(new LargeOnionPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeOnionPizza()); break; } } break; case 3: { System.out.println('You ordered Masala Pizza'); System.out.println('Enter the Masala pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Masala Pizza '); System.out.println(' 2. Medium Masala Pizza '); System.out.println(' 3. Large Masala Pizza '); System.out.println(' 4. Extra-Large Masala Pizza '); System.out.println('------------------------------------'); int masalapizzasize=Integer.parseInt(br.readLine()); switch(masalapizzasize) { case 1: itemsOrder.addItems(new SmallMasalaPizza()); break; case 2: itemsOrder.addItems(new MediumMasalaPizza()); break; case 3: itemsOrder.addItems(new LargeMasalaPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeMasalaPizza()); break; } } break; } } break;// Veg- pizza choice completed. case 2: { System.out.println('You ordered Non-Veg Pizza'); System.out.println(' '); System.out.println('Enter the Non-Veg pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Non-Veg Pizza '); System.out.println(' 2. Medium Non-Veg Pizza '); System.out.println(' 3. Large Non-Veg Pizza '); System.out.println(' 4. Extra-Large Non-Veg Pizza '); System.out.println('------------------------------------'); int nonvegpizzasize=Integer.parseInt(br.readLine()); switch(nonvegpizzasize) { case 1: itemsOrder.addItems(new SmallNonVegPizza()); break; case 2: itemsOrder.addItems(new MediumNonVegPizza()); break; case 3: itemsOrder.addItems(new LargeNonVegPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeNonVegPizza()); break; } } break; default: { break; } }//end of main Switch //continued?.. System.out.println(' Enter the choice of ColdDrink '); System.out.println('============================'); System.out.println(' 1. Pepsi '); System.out.println(' 2. Coke '); System.out.println(' 3. Exit '); System.out.println('============================'); int coldDrink=Integer.parseInt(br.readLine()); switch (coldDrink) { case 1: { System.out.println('You ordered Pepsi '); System.out.println('Enter the Pepsi Size '); System.out.println('------------------------'); System.out.println(' 1. Small Pepsi '); System.out.println(' 2. Medium Pepsi '); System.out.println(' 3. Large Pepsi '); System.out.println('------------------------'); int pepsisize=Integer.parseInt(br.readLine()); switch(pepsisize) { case 1: itemsOrder.addItems(new SmallPepsi()); break; case 2: itemsOrder.addItems(new MediumPepsi()); break; case 3: itemsOrder.addItems(new LargePepsi()); break; } } break; case 2: { System.out.println('You ordered Coke'); System.out.println('Enter the Coke Size'); System.out.println('------------------------'); System.out.println(' 1. Small Coke '); System.out.println(' 2. Medium Coke '); System.out.println(' 3. Large Coke '); System.out.println(' 4. Extra-Large Coke '); System.out.println('------------------------'); int cokesize=Integer.parseInt(br.readLine()); switch(cokesize) { case 1: itemsOrder.addItems(new SmallCoke()); break; case 2: itemsOrder.addItems(new MediumCoke()); break; case 3: itemsOrder.addItems(new LargeCoke()); break; } } break; default: { break; } }//End of the Cold-Drink switch return itemsOrder; } //End of the preparePizza() method </pre> <p>Step 15: <b>Create a BuilderDemo class that will use the OrderBuilder class.</b> </p> File: Prototype.java <pre> import java.io.IOException; public class BuilderDemo { public static void main(String[] args) throws IOException { // TODO code application logic here OrderBuilder builder=new OrderBuilder(); OrderedItems orderedItems=builder.preparePizza(); orderedItems.showItems(); System.out.println(' '); System.out.println('Total Cost : '+ orderedItems.getCost()); } }// End of the BuilderDemo class </pre> <hr> download this Builder Pattern Example <h4>Output</h4> </pre>Failas: MediumPepsi.java
public class MediumPepsi extends Pepsi { @Override public String name() { return '500 ml Pepsi'; } @Override public String size() { return 'Medium Size'; } @Override public float price() { return 35.0f; } }// End of the MediumPepsi classFailas: LargePepsi.java
public class LargePepsi extends Pepsi{ @Override public String name() { return '750 ml Pepsi'; } @Override public String size() { return 'Large Size'; } @Override public float price() { return 50.0f; } }// End of the LargePepsi class
12 veiksmas: Dabar sukurkite konkrečius poklasius SmallCoke, MediumCoke, LargeCoke, kurie apims abstrakčią klasę Koksas.
konvertuoti baitų masyvą į eilutęFailas: SmallCoke.java
public class SmallCoke extends Coke{ @Override public String name() { return '300 ml Coke'; } @Override public String size() { return 'Small Size'; } @Override public float price() { return 25.0f; } }// End of the SmallCoke classFailas: MediumCoke.java
public class MediumCoke extends Coke{ @Override public String name() { return '500 ml Coke'; } @Override public String size() { return 'Medium Size'; } @Override public float price() { return 35.0f; } }// End of the MediumCoke classFailas: LargeCoke.java
public class LargeCoke extends Coke { @Override public String name() { return '750 ml Coke'; } @Override public String size() { return 'Large Size'; } @Override public float price() { return 50.0f; } }// End of the LargeCoke class <p>Step 13: <b>Create an OrderedItems class that are having Item objects defined above.</b> </p> File: OrderedItems.java <pre> import java.util.ArrayList; import java.util.List; public class OrderedItems { List items=new ArrayList(); public void addItems(Item item){ items.add(item); } public float getCost(){ float cost=0.0f; for (Item item : items) { cost+=item.price(); } return cost; } public void showItems(){ for (Item item : items) { System.out.println('Item is:' +item.name()); System.out.println('Size is:' +item.size()); System.out.println('Price is: ' +item.price()); } } }// End of the OrderedItems class </pre> <p>Step 14: <b>Create an OrderBuilder class that will be responsible to create the objects of OrderedItems class.</b> </p> File: OrdereBuilder.java <pre> import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class OrderBuilder { public OrderedItems preparePizza() throws IOException{ OrderedItems itemsOrder=new OrderedItems(); BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); System.out.println(' Enter the choice of Pizza '); System.out.println('============================'); System.out.println(' 1. Veg-Pizza '); System.out.println(' 2. Non-Veg Pizza '); System.out.println(' 3. Exit '); System.out.println('============================'); int pizzaandcolddrinkchoice=Integer.parseInt(br.readLine()); switch(pizzaandcolddrinkchoice) { case 1:{ System.out.println('You ordered Veg Pizza'); System.out.println(' '); System.out.println(' Enter the types of Veg-Pizza '); System.out.println('------------------------------'); System.out.println(' 1.Cheeze Pizza '); System.out.println(' 2.Onion Pizza '); System.out.println(' 3.Masala Pizza '); System.out.println(' 4.Exit '); System.out.println('------------------------------'); int vegpizzachoice=Integer.parseInt(br.readLine()); switch(vegpizzachoice) { case 1: { System.out.println('You ordered Cheeze Pizza'); System.out.println('Enter the cheeze pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Cheeze Pizza '); System.out.println(' 2. Medium Cheeze Pizza '); System.out.println(' 3. Large Cheeze Pizza '); System.out.println(' 4. Extra-Large Cheeze Pizza '); System.out.println('------------------------------------'); int cheezepizzasize=Integer.parseInt(br.readLine()); switch(cheezepizzasize) { case 1: itemsOrder.addItems(new SmallCheezePizza()); break; case 2: itemsOrder.addItems(new MediumCheezePizza()); break; case 3: itemsOrder.addItems(new LargeCheezePizza()); break; case 4: itemsOrder.addItems(new ExtraLargeCheezePizza()); break; case 2: { System.out.println('You ordered Onion Pizza'); System.out.println('Enter the Onion pizza size'); System.out.println('----------------------------------'); System.out.println(' 1. Small Onion Pizza '); System.out.println(' 2. Medium Onion Pizza '); System.out.println(' 3. Large Onion Pizza '); System.out.println(' 4. Extra-Large Onion Pizza '); System.out.println('----------------------------------'); int onionpizzasize=Integer.parseInt(br.readLine()); switch(onionpizzasize) { case 1: itemsOrder.addItems(new SmallOnionPizza()); break; case 2: itemsOrder.addItems(new MediumOnionPizza()); break; case 3: itemsOrder.addItems(new LargeOnionPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeOnionPizza()); break; } } break; case 3: { System.out.println('You ordered Masala Pizza'); System.out.println('Enter the Masala pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Masala Pizza '); System.out.println(' 2. Medium Masala Pizza '); System.out.println(' 3. Large Masala Pizza '); System.out.println(' 4. Extra-Large Masala Pizza '); System.out.println('------------------------------------'); int masalapizzasize=Integer.parseInt(br.readLine()); switch(masalapizzasize) { case 1: itemsOrder.addItems(new SmallMasalaPizza()); break; case 2: itemsOrder.addItems(new MediumMasalaPizza()); break; case 3: itemsOrder.addItems(new LargeMasalaPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeMasalaPizza()); break; } } break; } } break;// Veg- pizza choice completed. case 2: { System.out.println('You ordered Non-Veg Pizza'); System.out.println(' '); System.out.println('Enter the Non-Veg pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Non-Veg Pizza '); System.out.println(' 2. Medium Non-Veg Pizza '); System.out.println(' 3. Large Non-Veg Pizza '); System.out.println(' 4. Extra-Large Non-Veg Pizza '); System.out.println('------------------------------------'); int nonvegpizzasize=Integer.parseInt(br.readLine()); switch(nonvegpizzasize) { case 1: itemsOrder.addItems(new SmallNonVegPizza()); break; case 2: itemsOrder.addItems(new MediumNonVegPizza()); break; case 3: itemsOrder.addItems(new LargeNonVegPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeNonVegPizza()); break; } } break; default: { break; } }//end of main Switch //continued?.. System.out.println(' Enter the choice of ColdDrink '); System.out.println('============================'); System.out.println(' 1. Pepsi '); System.out.println(' 2. Coke '); System.out.println(' 3. Exit '); System.out.println('============================'); int coldDrink=Integer.parseInt(br.readLine()); switch (coldDrink) { case 1: { System.out.println('You ordered Pepsi '); System.out.println('Enter the Pepsi Size '); System.out.println('------------------------'); System.out.println(' 1. Small Pepsi '); System.out.println(' 2. Medium Pepsi '); System.out.println(' 3. Large Pepsi '); System.out.println('------------------------'); int pepsisize=Integer.parseInt(br.readLine()); switch(pepsisize) { case 1: itemsOrder.addItems(new SmallPepsi()); break; case 2: itemsOrder.addItems(new MediumPepsi()); break; case 3: itemsOrder.addItems(new LargePepsi()); break; } } break; case 2: { System.out.println('You ordered Coke'); System.out.println('Enter the Coke Size'); System.out.println('------------------------'); System.out.println(' 1. Small Coke '); System.out.println(' 2. Medium Coke '); System.out.println(' 3. Large Coke '); System.out.println(' 4. Extra-Large Coke '); System.out.println('------------------------'); int cokesize=Integer.parseInt(br.readLine()); switch(cokesize) { case 1: itemsOrder.addItems(new SmallCoke()); break; case 2: itemsOrder.addItems(new MediumCoke()); break; case 3: itemsOrder.addItems(new LargeCoke()); break; } } break; default: { break; } }//End of the Cold-Drink switch return itemsOrder; } //End of the preparePizza() method </pre> <p>Step 15: <b>Create a BuilderDemo class that will use the OrderBuilder class.</b> </p> File: Prototype.java <pre> import java.io.IOException; public class BuilderDemo { public static void main(String[] args) throws IOException { // TODO code application logic here OrderBuilder builder=new OrderBuilder(); OrderedItems orderedItems=builder.preparePizza(); orderedItems.showItems(); System.out.println(' '); System.out.println('Total Cost : '+ orderedItems.getCost()); } }// End of the BuilderDemo class </pre> <hr> download this Builder Pattern Example <h4>Output</h4>
14 veiksmas: Sukurkite OrderBuilder klasę, kuri bus atsakinga už OrderedItems klasės objektų kūrimą.
Failas: OrdereBuilder.javaimport java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class OrderBuilder { public OrderedItems preparePizza() throws IOException{ OrderedItems itemsOrder=new OrderedItems(); BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); System.out.println(' Enter the choice of Pizza '); System.out.println('============================'); System.out.println(' 1. Veg-Pizza '); System.out.println(' 2. Non-Veg Pizza '); System.out.println(' 3. Exit '); System.out.println('============================'); int pizzaandcolddrinkchoice=Integer.parseInt(br.readLine()); switch(pizzaandcolddrinkchoice) { case 1:{ System.out.println('You ordered Veg Pizza'); System.out.println(' '); System.out.println(' Enter the types of Veg-Pizza '); System.out.println('------------------------------'); System.out.println(' 1.Cheeze Pizza '); System.out.println(' 2.Onion Pizza '); System.out.println(' 3.Masala Pizza '); System.out.println(' 4.Exit '); System.out.println('------------------------------'); int vegpizzachoice=Integer.parseInt(br.readLine()); switch(vegpizzachoice) { case 1: { System.out.println('You ordered Cheeze Pizza'); System.out.println('Enter the cheeze pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Cheeze Pizza '); System.out.println(' 2. Medium Cheeze Pizza '); System.out.println(' 3. Large Cheeze Pizza '); System.out.println(' 4. Extra-Large Cheeze Pizza '); System.out.println('------------------------------------'); int cheezepizzasize=Integer.parseInt(br.readLine()); switch(cheezepizzasize) { case 1: itemsOrder.addItems(new SmallCheezePizza()); break; case 2: itemsOrder.addItems(new MediumCheezePizza()); break; case 3: itemsOrder.addItems(new LargeCheezePizza()); break; case 4: itemsOrder.addItems(new ExtraLargeCheezePizza()); break; case 2: { System.out.println('You ordered Onion Pizza'); System.out.println('Enter the Onion pizza size'); System.out.println('----------------------------------'); System.out.println(' 1. Small Onion Pizza '); System.out.println(' 2. Medium Onion Pizza '); System.out.println(' 3. Large Onion Pizza '); System.out.println(' 4. Extra-Large Onion Pizza '); System.out.println('----------------------------------'); int onionpizzasize=Integer.parseInt(br.readLine()); switch(onionpizzasize) { case 1: itemsOrder.addItems(new SmallOnionPizza()); break; case 2: itemsOrder.addItems(new MediumOnionPizza()); break; case 3: itemsOrder.addItems(new LargeOnionPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeOnionPizza()); break; } } break; case 3: { System.out.println('You ordered Masala Pizza'); System.out.println('Enter the Masala pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Masala Pizza '); System.out.println(' 2. Medium Masala Pizza '); System.out.println(' 3. Large Masala Pizza '); System.out.println(' 4. Extra-Large Masala Pizza '); System.out.println('------------------------------------'); int masalapizzasize=Integer.parseInt(br.readLine()); switch(masalapizzasize) { case 1: itemsOrder.addItems(new SmallMasalaPizza()); break; case 2: itemsOrder.addItems(new MediumMasalaPizza()); break; case 3: itemsOrder.addItems(new LargeMasalaPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeMasalaPizza()); break; } } break; } } break;// Veg- pizza choice completed. case 2: { System.out.println('You ordered Non-Veg Pizza'); System.out.println(' '); System.out.println('Enter the Non-Veg pizza size'); System.out.println('------------------------------------'); System.out.println(' 1. Small Non-Veg Pizza '); System.out.println(' 2. Medium Non-Veg Pizza '); System.out.println(' 3. Large Non-Veg Pizza '); System.out.println(' 4. Extra-Large Non-Veg Pizza '); System.out.println('------------------------------------'); int nonvegpizzasize=Integer.parseInt(br.readLine()); switch(nonvegpizzasize) { case 1: itemsOrder.addItems(new SmallNonVegPizza()); break; case 2: itemsOrder.addItems(new MediumNonVegPizza()); break; case 3: itemsOrder.addItems(new LargeNonVegPizza()); break; case 4: itemsOrder.addItems(new ExtraLargeNonVegPizza()); break; } } break; default: { break; } }//end of main Switch //continued?.. System.out.println(' Enter the choice of ColdDrink '); System.out.println('============================'); System.out.println(' 1. Pepsi '); System.out.println(' 2. Coke '); System.out.println(' 3. Exit '); System.out.println('============================'); int coldDrink=Integer.parseInt(br.readLine()); switch (coldDrink) { case 1: { System.out.println('You ordered Pepsi '); System.out.println('Enter the Pepsi Size '); System.out.println('------------------------'); System.out.println(' 1. Small Pepsi '); System.out.println(' 2. Medium Pepsi '); System.out.println(' 3. Large Pepsi '); System.out.println('------------------------'); int pepsisize=Integer.parseInt(br.readLine()); switch(pepsisize) { case 1: itemsOrder.addItems(new SmallPepsi()); break; case 2: itemsOrder.addItems(new MediumPepsi()); break; case 3: itemsOrder.addItems(new LargePepsi()); break; } } break; case 2: { System.out.println('You ordered Coke'); System.out.println('Enter the Coke Size'); System.out.println('------------------------'); System.out.println(' 1. Small Coke '); System.out.println(' 2. Medium Coke '); System.out.println(' 3. Large Coke '); System.out.println(' 4. Extra-Large Coke '); System.out.println('------------------------'); int cokesize=Integer.parseInt(br.readLine()); switch(cokesize) { case 1: itemsOrder.addItems(new SmallCoke()); break; case 2: itemsOrder.addItems(new MediumCoke()); break; case 3: itemsOrder.addItems(new LargeCoke()); break; } } break; default: { break; } }//End of the Cold-Drink switch return itemsOrder; } //End of the preparePizza() method
15 veiksmas: Sukurkite „BuilderDemo“ klasę, kuri naudos „OrderBuilder“ klasę.
Failas: Prototype.javaimport java.io.IOException; public class BuilderDemo { public static void main(String[] args) throws IOException { // TODO code application logic here OrderBuilder builder=new OrderBuilder(); OrderedItems orderedItems=builder.preparePizza(); orderedItems.showItems(); System.out.println(' '); System.out.println('Total Cost : '+ orderedItems.getCost()); } }// End of the BuilderDemo class
atsisiųskite šį „Builder“ modelio pavyzdį