File tree Expand file tree Collapse file tree
pattern/src/com/premaseem/builder Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .premaseem .builder ;
2+
3+ import com .premaseem .room .Room ;
4+
5+ import java .util .ArrayList ;
6+ import java .util .List ;
7+
8+ /*
9+ @author: Aseem Jain
10+ @title: Design Patterns with Java 9
11+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
12+ */
13+ /* "Product" */
14+ public class House {
15+ List <Room > rooms = new ArrayList <>();
16+ private String exteriorColor = "while" ;
17+
18+ public String getExteriorColor () {
19+ return exteriorColor ;
20+ }
21+
22+ public void setExteriorColor (String exteriorColor ) {
23+ this .exteriorColor = exteriorColor ;
24+ }
25+
26+ @ Override
27+ public String toString () {
28+ System .out .println ("house has total rooms " + rooms .size ());
29+ System .out .println ("house has color " + getExteriorColor ());
30+ return "" ;
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem .builder ;
2+
3+ /*
4+ @author: Aseem Jain
5+ @title: Design Patterns with Java 9
6+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
7+ */
8+ /* "Abstract Builder" */
9+ public abstract class HouseBuilder {
10+ public House getHouse () {
11+ return house ;
12+ }
13+
14+ private House house =null ;
15+
16+ public HouseBuilder (){
17+ house = new House ();
18+ }
19+
20+ public abstract void addRooms ();
21+
22+ public void addSecuritySystem (){
23+ System .out .println ("adding security system" );
24+ }
25+
26+ public void addPlumbingSystem (){
27+ System .out .println ("adding plumbing system" );
28+ }
29+
30+ public void addAirConditionerSystem (){
31+ System .out .println ("adding air conditioning system" );
32+ }
33+
34+ public void paintHouse (String color ){
35+ System .out .println ("paiting house with color " + color );
36+ house .setExteriorColor (color );
37+ }
38+
39+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem .builder ;
2+
3+ import com .premaseem .room .BathRoom ;
4+ import com .premaseem .room .BedRoom ;
5+ import com .premaseem .room .LivingRoom ;
6+
7+ /*
8+ @author: Aseem Jain
9+ @title: Design Patterns with Java 9
10+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
11+ */
12+
13+ /* "ConcreteBuilder" */
14+ public class OneBedroomHouseBuilder extends HouseBuilder {
15+
16+ @ Override
17+ public void addRooms () {
18+ getHouse ().rooms .add (new BathRoom ());
19+ getHouse ().rooms .add (new BedRoom ());
20+ getHouse ().rooms .add (new LivingRoom ());
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem .builder ;
2+
3+ import com .premaseem .room .BathRoom ;
4+ import com .premaseem .room .BedRoom ;
5+ import com .premaseem .room .LivingRoom ;
6+
7+ /*
8+ @author: Aseem Jain
9+ @title: Design Patterns with Java 9
10+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
11+ */
12+
13+ /* "ConcreteBuilder" */
14+ public class TwoBedroomHouseBuilder extends HouseBuilder {
15+
16+ @ Override
17+ public void addRooms () {
18+ getHouse ().rooms .add (new BathRoom ());
19+ getHouse ().rooms .add (new BedRoom ());
20+ getHouse ().rooms .add (new LivingRoom ());
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments