Python code, 用 “builder” pattern refactoring 谢谢!

来源:百度知道 编辑:UC知道 时间:2024/05/09 14:25:29
python code, 帮我用builder pattern 原理改造一下谢谢啦!

里面的comments我也没删,希望大家帮忙哈!

class PizzaKitMatic:
def __init__(self, type):
self.type = type
self.ingedients = []

def makePizza(self):
"""This design is inflexible.
The case statement in this method
will forever have to be edited and extended
as new types of pizzas are added to the range.
"""
self.ingedients.append("Soft Crust Base")
# add main topping
if self.type == 'Veggie':
self.ingedients.append("Mushrooms")
elif self.type == 'Chicken':
self.ingedients.append("Chicken")

# add cheese
if self.type == 'Veggie':
self.ingedients.append("Moz")
e

共 1 条
class PizzaKitMatic:
def __init__(self, type):
self.type = type
self.ingedients = []

def makePizza(self):
"""This design is inflexible.
The case statement in this method
will forever have to be edited and extended
as new types of pizzas are added to the range.
"""
self.ingedients.append("Soft Crust Base")
# add main topping
if self.type == 'Veggie':
self.ingedients.append("Mushrooms")
elif self.type == 'Chicken':
self.ingedients.append("Chicken")

# add cheese
if self.type == 'Veggie':
self.ingedients.append("Moz")
elif self.type == 'Chicken':
self.ingedients.append("Blue Cheese")

# add additional topping
if self.type == 'Veggie':
self.ingedients.append("Sun Dried Tomatoes & Olives")
el