|
10 | 10 | from its actual representation (generally for abstraction).
|
11 | 11 |
|
12 | 12 | *What does this example do?
|
13 |
| -This particular example uses a Director to abtract the |
| 13 | +This particular example uses a director function to abtract the |
14 | 14 | construction of a building. The user specifies a Builder (House or
|
15 | 15 | Flat) and the director specifies the methods in the order necessary
|
16 |
| -creating a different building dependding on the specified |
| 16 | +creating a different building depending on the specified |
17 | 17 | specification (through the Builder class).
|
18 | 18 |
|
19 | 19 | @author: Diogenes Augusto Fernandes Herminio <[email protected]>
|
|
29 | 29 | """
|
30 | 30 |
|
31 | 31 |
|
32 |
| -# Director |
33 |
| -class Director(object): |
34 |
| - |
35 |
| - def __init__(self): |
36 |
| - self.builder = None |
37 |
| - |
38 |
| - def construct_building(self): |
39 |
| - self.builder.new_building() |
40 |
| - self.builder.build_floor() |
41 |
| - self.builder.build_size() |
42 |
| - |
43 |
| - def get_building(self): |
44 |
| - return self.builder.building |
| 32 | +def construct_building(builder): |
| 33 | + builder.new_building() |
| 34 | + builder.build_floor() |
| 35 | + builder.build_size() |
| 36 | + return builder.building |
45 | 37 |
|
46 | 38 |
|
47 | 39 | # Abstract Builder
|
@@ -93,14 +85,9 @@ def __repr__(self):
|
93 | 85 |
|
94 | 86 | # Client
|
95 | 87 | if __name__ == "__main__":
|
96 |
| - director = Director() |
97 |
| - director.builder = BuilderHouse() |
98 |
| - director.construct_building() |
99 |
| - building = director.get_building() |
| 88 | + building = construct_building(BuilderHouse()) |
100 | 89 | print(building)
|
101 |
| - director.builder = BuilderFlat() |
102 |
| - director.construct_building() |
103 |
| - building = director.get_building() |
| 90 | + building = construct_building(BuilderFlat()) |
104 | 91 | print(building)
|
105 | 92 |
|
106 | 93 | ### OUTPUT ###
|
|
0 commit comments