Created
November 25, 2017 14:03
-
-
Save mhtmalpani/aa3dd31f96aaf800439fdf302f90921e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Subway { | |
//Member Variables | |
private String bread; | |
private boolean toast; | |
private boolean veg; | |
private boolean nonVeg; | |
private boolean onion; | |
private boolean tomato; | |
private boolean olives; | |
private boolean chicken; | |
private boolean mutton; | |
private String cheese; | |
//Constructor | |
Subway(Builder builder) { | |
this.bread = builder.bread; | |
this.toast = builder.toast; | |
this.veg = builder.veg; | |
this.nonVeg = builder.nonVeg; | |
this.onion = builder.onion; | |
this.tomato = builder.tomato; | |
this.olives = builder.olives; | |
this.chicken = builder.chicken; | |
this.mutton = builder.mutton; | |
this.cheese = builder.cheese; | |
} | |
public String getBread() { | |
return bread; | |
} | |
public boolean isToast() { | |
return toast; | |
} | |
public boolean isVeg() { | |
return veg; | |
} | |
public boolean isNonVeg() { | |
return nonVeg; | |
} | |
public boolean isOnion() { | |
return onion; | |
} | |
public boolean isTomato() { | |
return tomato; | |
} | |
public boolean isOlives() { | |
return olives; | |
} | |
public boolean isChicken() { | |
return chicken; | |
} | |
public boolean isMutton() { | |
return mutton; | |
} | |
public String getCheese() { | |
return cheese; | |
} | |
public static Bread builder() { | |
return new Builder(); | |
} | |
//Builder class | |
public static class Builder implements Bread, Toast, Type, Veg, NonVeg, Extra { | |
private String bread; | |
private boolean toast; | |
private boolean veg; | |
private boolean nonVeg; | |
private boolean onion; | |
private boolean tomato; | |
private boolean olives; | |
private boolean chicken; | |
private boolean mutton; | |
private String cheese; | |
Builder() { | |
this.bread = null; | |
this.toast = false; | |
this.veg = false; | |
this.nonVeg = false; | |
this.onion = false; | |
this.tomato = false; | |
this.olives = false; | |
this.chicken = false; | |
this.mutton = false; | |
this.cheese = null; | |
} | |
public Toast bread(String bread) { | |
this.bread = bread; | |
return this; | |
} | |
public Type toast(boolean toast) { | |
this.toast = toast; | |
return this; | |
} | |
public Veg veg() { | |
this.veg = true; | |
return this; | |
} | |
public NonVeg nonVeg() { | |
this.nonVeg = true; | |
return this; | |
} | |
public Veg onion() { | |
this.onion = true; | |
return this; | |
} | |
public Veg tomato() { | |
this.tomato = true; | |
return this; | |
} | |
public Veg olives() { | |
this.olives = true; | |
return this; | |
} | |
public Extra prepare() { | |
return this; | |
} | |
public Veg chicken() { | |
this.chicken = true; | |
return this; | |
} | |
public Veg mutton() { | |
this.mutton = true; | |
return this; | |
} | |
public Builder cheese(String cheese) { | |
this.cheese = cheese; | |
return this; | |
} | |
public Subway build() { | |
return new Subway(this); | |
} | |
} | |
interface Bread { | |
Toast bread(String bread); | |
} | |
interface Toast { | |
Type toast(boolean toast); | |
} | |
interface Type { | |
Veg veg(); | |
NonVeg nonVeg(); | |
} | |
interface Veg { | |
Veg onion(); | |
Veg tomato(); | |
Veg olives(); | |
Extra prepare(); | |
} | |
interface NonVeg { | |
Veg chicken(); | |
Veg mutton(); | |
} | |
//Any extra non mandatory items | |
interface Extra { | |
Extra cheese(String cheese); | |
Subway build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment