class PizzaShop: def __init__(self): self.sever = Sever('Pat') self.chef = PizzaRobot('Bob') self.oven = Oven() def order(self, name): customer = Customer(name) customer.order(self.sever) self.chef.work(); self.oven.bake(); customer.pay(self.sever)
class PizzaShop: def __init__(self): self.chief=PizzaRobot("Pat") self.server=Server("Bob") self.oven=Oven() def order(self,name): customer=Customer(name) customer.order(self.server) self.chief.work() self.oven.bake() customer.pay(self.server)
class PizzaShop: # Пиццерия def __init__(self): self.server = Server('Pat') # Официант который возится с клиетом self.chef = PizzaRobot('Bob') # Повар который делает пиццу self.oven = Oven() # Печь которая печет :) def order(self,name): # Сцена заказа customer = Customer(name) # Берем имя клиента customer.order(self.server) # Клиент делает заказ у Pat self.chef.work() # Bob готовит self.oven.bake() # Печь - печет :) customer.pay(self.server) # Клиент платит :)
class PizzaShop: def __init__(self): self.server = Server('Pat') self.chef = PizzaRobot('Bob') self.oven = Oven() def order(self, name): customer = Customer(name) customer.order(self.server) self.chef.work() self.oven.bake() customer.pay(self.server)
class PizzaShop: def __init__(self): self.server = Server('Pat') self.chef = PizzaRobot('Bob') self.oven = Oven() def order(self,name): customer = Customer(name) customer.order(self.server) self.chef.work() self.oven.bake() customer.pay(self.server) #The whole class reads nice
class PizzaShop: def __init__(self): self.server = Server('Pat') # Embed other objects self.chef = PizzaRobot('Bob') # A robot named bob self.oven = Oven() def order(self, name): customer = Customer(name) # Activate other objects customer.order(self.server) # Customer orders from server self.chef.work() self.oven.bake() customer.pay(self.server)
class PizzaShop: def __init__(self): self.server = Server('Peat') # Встроить другие обьекты self.chef = PizzaRobot('Bob') # Робот по имени Боб self.oven = Oven() def order(self, name): customer = Customer(name) # Активизировать другие объекты customer.order(self.server) # Клиент делает заказ официанту self.chef.work() self.oven.bake() customer.pay(self.server)
class PizzaShop: def __init__(self): self.server = Server('Pat') # Embed other objects self.chef = PizzaRobot('Bob') # A robot named bob self.oven = Oven() def order(self, name): customer = Customer(name) customer.order(self.server) self.chef.work() self.oven.bake() customer.pay(self.server)
class PizzaShop: def __init__(self): self.server = Server('Pat') # 다른 객체를 내포시킴 self.chef = PizzaRobot('Bob') # bob이라는 이름의 로봇 self.oven = Oven() def order(self, name): customer = Customer(name) # 다른 객체를 활성화 customer.order(self.server) # 서빙직원으로부터 고객 주문을 받음 self.chef.work() self.oven.bake() customer.pay(self.server)
class PizzaShop: """Inception and activation of other objects """ def __init__(self): # inception self.server = Server('Pat') self.chef = PizzaRobot('Bob') self.oven = Oven() def order(self, name): # activation customer = Customer(name) customer.order(self.server) self.chef.work() self.oven.bake() customer.pay(self.server)
class Server(Employee): def __init__(self, name): Employee.__init__(self, name, 40000) def work(self): print(self.name, "interfaces with customer") class PizzaRobot(Chef): def __init__(self, name): Chef.__init__(self, name) def work(self): print(self.name, "makes pizza") if __name__ == "__main__": bob = PizzaRobot('bob') # Make a robot named bob print(bob) # Run inherited __repr__ bob.work() # Run type-specific action bob.giveRaise(0.20) # Give bob a 20% raise print(bob); print() for klass in Employee, Chef, Server, PizzaRobot: obj = klass(klass.__name__) obj.work() C:\python\examples> python employees.py ### file: pizzashop.py
def __init__ (self, name): Employee.__init__ (self, name, 40000) def work(self): print(self.name, "interfaces with customer") # взаимодействует # с клиентом class PizzaRobot(Chef): def __init__ (self, name): Chef.__init__ (self, name) def work(self): print(self.name, "makes pizza") # готовит пиццу if __name__ == "__main__" : bob = PizzaRobot('bob') # Создать робота по имени bob print (bob) # Выполняется унаследованный метод__ repr__ bob.work () # Выполняется действие, специфичное для типа bob.giveRaise (0.20) # Повысить зарплату роботу bob на 20% print(bob); print() for klass in Employee, Chef, Server, PizzaRobot: obj = klass(klass.__name__ ) obj.work() ______________________________________________________________ from __future__ import print_function from employees import PizzaRobot, Server class Customer: def __init__ (self, name): self.name = name def order(self, server): print(self.name, "orders from", def pay(self, server): print(self.name,