Last active
May 17, 2020 10:07
-
-
Save yogeshjoshi/14b678d5d5755b70fcd1a5d402fa7ca4 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 MyPizza{ | |
private int size; | |
private boolean cheese; | |
private boolean pepperoni; | |
private boolean bacon; | |
private boolean veggies; | |
private boolean blackPepper; | |
public MyPizza(int size,boolean cheese, boolean pepperoni, boolean bacon, boolean veggies, boolean blackPepper){ | |
this.size = size; | |
this.cheese = cheese; | |
this.pepperoni = pepperoni; | |
this.bacon = bacon; | |
this.veggies = veggies; | |
this.blackPepper = blackPepper; | |
} | |
//No Setter to Impose Immutibility Of the Object | |
public int getSize(){ | |
return size; | |
} | |
public boolean isPepperoni(){ | |
return pepperoni; | |
} | |
public boolean isBacon(){ | |
return bacon; | |
} | |
public boolean isVeggies(){ | |
return veggies; | |
} | |
static class Builder{ | |
private int size; | |
private boolean cheese; | |
private boolean pepperoni; | |
private boolean bacon; | |
private boolean veggies; | |
private boolean blackPepper; | |
public Builder setSize(int size){ | |
this.size = size; | |
return this; | |
} | |
public Builder setPepperoni(boolean pepperoni){ | |
this.pepperoni = pepperoni; | |
return this; | |
} | |
public Builder setBacon(boolean bacon){ | |
this.bacon = bacon; | |
return this; | |
} | |
public Builder setVeggies(boolean veggies){ | |
this.veggies = veggies; | |
return this; | |
} | |
public Builder setBlackPepper(boolean blackPepper){ | |
this.blackPepper = blackPepper; | |
return this; | |
} | |
public MyPizza build(){ | |
return new MyPizza(size,cheese,pepperoni,bacon,veggies,blackPepper); | |
//See No need to remember the order of arguments in constructor, while coding you only needs to remember | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment