Design Pattern: Builder
a)Builder Design Pattern:
In builder design pattern, we use same logic like abstract factory but only difference is that apart from implementing methods of abstract factory class, the concrete class also has extra methods which will impart additional functionality to the final user who will use that concrete class.
Refer to abstract factory page for understanding the logic.
Only change is in concrete class (JuiceShop), apart from methods for creating chair, table, shelf & bottles, we have extra methods like designRoom, ventilationSystem, paymentSystem, etc.
4) Create concrete class which will implement above abstract class and its methods as per requirements
public class JuiceShop implements shopSetUp(){
Chair chair;
Shelf shelf;
Table table;
Bottle bottle;
//All the above classes will be used in methods below
public chair createChair(String material){
if(material.equalsIgnoreCase("WOODEN")){
chair = new WoodenChair();
else if(material.equalsIgnoreCase("METAL")){
chair = new MetalChair();
else if(material.equalsIgnoreCase("PLASTIC")){
chair = new PlasticChair();
else if(material.equalsIgnoreCase("FIBREGLASS"){
chair = new FibreChair();
else
chair = null;
return chair;
}
public table createTable(String material){
if(material.equalsIgnoreCase("WOODEN")){
table = new WoodenTable();
else if(material.equalsIgnoreCase("METAL")){
table = new MetalTable();
else if(material.equalsIgnoreCase("PLASTIC")){
table = new PlasticTable();
else if(material.equalsIgnoreCase("FIBREGLASS"){
table = new FibreTable();
else
table = null;
return table;
}
public shelf createShelf(String material){
if(material.equalsIgnoreCase("WOODEN")){
shelf = new WoodenShelf();
else if(material.equalsIgnoreCase("METAL")){
shelf = new MetalShelf();
else if(material.equalsIgnoreCase("PLASTIC")){
shelf = new PlasticShelf();
else if(material.equalsIgnoreCase("FIBREGLASS"){
shelf = new FibreShelf();
else
shelf = null;
return shelf;
}
public bottle createBottle(String material){
if(material.equalsIgnoreCase("BAMBOO")){
bottle = new BambooBottle();
else if(material.equalsIgnoreCase("METAL")){
bottle = new MetalBottle();
else if(material.equalsIgnoreCase("PLASTIC")){
bottle = new PlasticBottle();
else if(material.equalsIgnoreCase("FIBREGLASS"){
bottle = new FibreBottle();
else
bottle = null;
return bottle;
}
public String paymentSystem(String location){
String payment;
if(location.equalsIgnoreCase("as shop"){
payment = "Cash & card";
else if(location.equalsIgnoreCase("on stall"){
payment = "Cash & mobile digital";
else if(location.equalsIgnoreCase("in mall"){
payment = "Cash, card & online digital";
else
payment = "Cash";
}
public String ventilationSystem(String location){
String ventilation;
if(location.equalsIgnoreCase("as shop"){
ventilation = "Fan & natural vents";
else if(location.equalsIgnoreCase("on stall"){
ventilation = "Fan";
else if(location.equalsIgnoreCase("in mall"){
ventilation = "Fan & AC";
else
ventilation = "natural ventilation";
}
public String designRoom(String location){
String space;
if(location.equalsIgnoreCase("as shop"){
space = "Buy shop as per expected customer capacity & goods";
else if(location.equalsIgnoreCase("on stall"){
space = "Buy simple cart with minimal size to accommodate goods";
else if(location.equalsIgnoreCase("in mall"){
space = "Standard shop outlet as franchaise or outlet";
else
space = "needs calculation to decide";
}
}
No comments:
Post a Comment