Skip to content

Commit e35e7d9

Browse files
authored
Merge pull request cundi#6 from caimaoy/bug-fix-modify-words
修改笔误
2 parents 36c4511 + 29c5c40 commit e35e7d9

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

第二章-构造器模式.md

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ to return the final object when it needs it [GOF95, page 113], [j.mp/builderpat]
5656

5757
The new computer analogy might help to distinguish between a Builder pattern and a Factory pattern. Assume that you want to buy a new computer. If you decide to buy a specific preconfigured computer model, for example, the latest Apple 1.4 GHz Mac mini, you use the Factory pattern. All the hardware specifications are already predefined by the manufacturer, who knows what to do without consulting you. The manufacturer typically receives just a single instruction. Code-wise, this would look like the following (*apple-factory.py*):
5858

59-
新计算机的分析有助于区别构造器模式和工厂模式。假设你需要买一台新电脑。如果你决定买预先配置好的电脑,例如最新的Apple 1.4Ghz Mac mini,你使用的是工厂模式。所有硬件规格都已经由厂商预定义了,厂家不用问你也知道该干什么。厂商通畅只会收到一条指令。代码使人明了,其内容如下(*apple-factory.py*):
59+
新计算机的分析有助于区别构造器模式和工厂模式。假设你需要买一台新电脑。如果你决定买预先配置好的电脑,例如最新的Apple 1.4Ghz Mac mini,你使用的是工厂模式。所有硬件规格都已经由厂商预定义了,厂家不用问你也知道该干什么。厂商通常只会收到一条指令。代码使人明了,其内容如下(*apple-factory.py*):
6060

6161
```python
6262
MINI14 = '1.4GHz Mac mini'
@@ -183,7 +183,7 @@ not supposed to be instantiated directly. A builder creates an instance of the e
183183
- To clarify the fact that the end product is typically minimal does not mean that you should never assign it any responsibilities
184184
- To promote code reuse through composition [GOF95, page 32]
185185

186-
- 要说明的是,终端产品通畅是最小化的,但是这并不意味着你从此就不能让它承担任何的职责
186+
- 要说明的是,终端产品通常是最小化的,但是这并不意味着你从此就不能让它承担任何的职责
187187
- 通过使用合成来提升代码的复用性
188188

189189
```python
@@ -360,7 +360,6 @@ class MargaritaBuilder:
360360
self.pizza = Pizza('margarita')
361361
self.progress = PizzaProgress.queued
362362
self.baking_time = 5 # in seconds for the sake of the
363-
example
364363

365364
def prepare_dough(self):
366365
self.progress = PizzaProgress.preparation
@@ -402,53 +401,53 @@ class CreamyBaconBuilder:
402401
self.pizza = Pizza('creamy bacon')
403402
self.progress = PizzaProgress.queued
404403
self.baking_time = 7 # in seconds for the sake of the
405-
example
406404

407405
def prepare_dough(self):
408-
self.progress = PizzaProgress.preparation
409-
self.pizza.prepare_dough(PizzaDough.thick)
406+
self.progress = PizzaProgress.preparation
407+
self.pizza.prepare_dough(PizzaDough.thick)
410408

411409
def add_sauce(self):
412-
print('adding the crème fraîche sauce to your creamy bacon')
413-
self.pizza.sauce = PizzaSauce.creme_fraiche
414-
time.sleep(STEP_DELAY)
415-
print('done with the crème fraîche sauce')
410+
print('adding the crème fraîche sauce to your creamy bacon')
411+
self.pizza.sauce = PizzaSauce.creme_fraiche
412+
time.sleep(STEP_DELAY)
413+
print('done with the crème fraîche sauce')
416414

417415
def add_topping(self):
418-
print('adding the topping (mozzarella, bacon, ham, mushrooms, red onion, oregano) to your creamy bacon')
419-
self.pizza.topping.append([t for t in
420-
(PizzaTopping.mozzarella, PizzaTopping.bacon,
421-
PizzaTopping.ham,PizzaTopping.mushrooms,
422-
PizzaTopping.red_onion, PizzaTopping.oregano)])
423-
time.sleep(STEP_DELAY)
424-
print('done with the topping (mozzarella, bacon, ham, mushrooms, red onion, oregano)')
416+
print('adding the topping (mozzarella, bacon, ham, mushrooms, red onion, oregano) to your creamy bacon')
417+
self.pizza.topping.append([t for t in
418+
(PizzaTopping.mozzarella, PizzaTopping.bacon,
419+
PizzaTopping.ham,PizzaTopping.mushrooms,
420+
PizzaTopping.red_onion, PizzaTopping.oregano)])
421+
time.sleep(STEP_DELAY)
422+
print('done with the topping (mozzarella, bacon, ham, mushrooms, red onion, oregano)')
425423

426424
def bake(self):
427-
self.progress = PizzaProgress.baking
428-
print('baking your creamy bacon for {} seconds'.format(self.baking_time))
429-
time.sleep(self.baking_time)
430-
self.progress = PizzaProgress.ready
431-
print('your creamy bacon is ready')
425+
self.progress = PizzaProgress.baking
426+
print('baking your creamy bacon for {} seconds'.format(self.baking_time))
427+
time.sleep(self.baking_time)
428+
self.progress = PizzaProgress.ready
429+
print('your creamy bacon is ready')
432430

433431

434-
class Waiter:
435-
def __init__(self):
436-
self.builder = None
437-
def construct_pizza(self, builder):
438-
self.builder = builder
439-
[step() for step in (builder.prepare_dough,
440-
builder.add_sauce, builder.add_topping, builder.bake)]
441-
@property
442-
def pizza(self):
443-
return self.builder.pizza
444-
445-
def validate_style(builders):
446-
try:
447-
pizza_style = input('What pizza would you like, [m]argarita or [c]reamy bacon? ')uilder = builders[pizza_style]() valid_input = True
448-
except KeyError as err:
449-
print('Sorry, only margarita (key m) and creamy bacon (key c) are available')
450-
return (False, None)
451-
return (True, builder)
432+
class Waiter:
433+
def __init__(self):
434+
self.builder = None
435+
def construct_pizza(self, builder):
436+
self.builder = builder
437+
[step() for step in (builder.prepare_dough,
438+
builder.add_sauce, builder.add_topping, builder.bake)]
439+
@property
440+
def pizza(self):
441+
return self.builder.pizza
442+
def validate_style(builders):
443+
try:
444+
pizza_style = input('What pizza would you like,[m]argarita or [c]reamy bacon? ')
445+
builder = builders[pizza_style]()
446+
valid_input = True
447+
except KeyError as err:
448+
print('Sorry, only margarita (key m) and creamy bacon (key c) are available')
449+
return (False, None)
450+
return (True, builder)
452451

453452

454453
def main():

0 commit comments

Comments
 (0)