@@ -66,6 +66,36 @@ def __str__(self):
66
66
+ str (self .computer .storage )) + ","
67
67
+ str (self .computer .Screen ))
68
68
69
+ class BudgetComputerBuilder (ComputerBuilder ):
70
+ def __init__ (self ):
71
+ self .computer = Computer ("Intel i3" , "8GB" , "250MB HD" ,
72
+ "NVIDIA" ,
73
+ screen = "13 Inch" )
74
+
75
+ def build_cpu (self ):
76
+ self .computer .CPU = "Intel i3"
77
+
78
+ def build_ram (self ):
79
+ self .computer .RAM = "8GB"
80
+
81
+ def build_storage (self ):
82
+ self .computer .storage = "250MB HD"
83
+
84
+ def build_gpu (self ):
85
+ self .computer .GPU = "NVIDIA"
86
+
87
+ def build_screen (self ):
88
+ self .computer .Screen = "13 Inch"
89
+
90
+ def get_computer (self ):
91
+ return self .computer
92
+
93
+ def __str__ (self ):
94
+ return (((f"\n High End Computer : " + str (self .computer .CPU ) +
95
+ "," + str (self .computer .RAM )) + ","
96
+ + str (self .computer .storage )) + ","
97
+ + str (self .computer .Screen ))
98
+
69
99
70
100
# Director
71
101
class ComputerDirector :
@@ -86,10 +116,25 @@ def construct_computer(self):
86
116
director .construct_computer ()
87
117
computer = builder .get_computer ()
88
118
89
- # Output
90
- print ("Computer specs:" )
91
- print (f"CPU: { computer .CPU } " )
92
- print (f"RAM: { computer .RAM } " )
93
- print (f"Storage: { computer .storage } " )
94
- print (f"GPU: { computer .GPU } " )
95
- print (f"Screen: { computer .Screen } " )
119
+
120
+ def print_spec (model : str , computer : Computer ) -> None :
121
+ print (f"\n Computer specs: { model } " )
122
+ print (f"CPU: { computer .CPU } " )
123
+ print (f"RAM: { computer .RAM } " )
124
+ print (f"Storage: { computer .storage } " )
125
+ print (f"GPU: { computer .GPU } " )
126
+ print (f"Screen: { computer .Screen } " )
127
+
128
+
129
+ # Output for a High End model
130
+ print_spec ("High End" , computer )
131
+
132
+ # Client code
133
+ builder = BudgetComputerBuilder ()
134
+ director = ComputerDirector (builder )
135
+ director .construct_computer ()
136
+ computer = builder .get_computer ()
137
+
138
+ # Output for a Budget model
139
+ print_spec ("Budget" , computer )
140
+
0 commit comments