mixin_2.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. class BasePizza:
  2. BASE_PIZZA_PRICE = 15
  3. def __init__(self, name, price):
  4. self.name = name
  5. self.price = price
  6. self.toppings = ['cheese']
  7. def __str__(self):
  8. return f"{self.name} with {self.toppings}, ${self.price:.2f}"
  9. class PepperoniMixin:
  10. def add_pepperoni(self):
  11. print("Adding pepperoni!")
  12. self.price += 5
  13. self.toppings += ['pepperoni']
  14. class MushroomMixin:
  15. def add_mushrooms(self):
  16. print("Adding mushrooms!")
  17. self.price += 3
  18. self.toppings += ['mushrooms']
  19. class OnionMixin:
  20. def add_onion(self):
  21. print("Adding onion!")
  22. self.price += 2
  23. self.toppings += ['onion']
  24. class BaconMixin:
  25. def add_bacon(self):
  26. print("Adding bacon!")
  27. self.price += 6
  28. self.toppings += ['bacon']
  29. class OlivesMixin:
  30. def add_olives(self):
  31. print("Adding olives!")
  32. self.price += 1
  33. self.toppings += ['olives']
  34. class HamMixin:
  35. def add_ham(self):
  36. print("Adding ham!")
  37. self.price += 7
  38. self.toppings += ['ham']
  39. class PepperMixin:
  40. def add_pepper(self):
  41. print("Adding pepper!")
  42. self.price += 3
  43. self.toppings += ['pepper']
  44. class ChickenMixin:
  45. def add_chicken(self):
  46. print("Adding chicken!")
  47. self.price += 5
  48. self.toppings += ['chicken']
  49. class OlivesPizza(BasePizza, OlivesMixin):
  50. def __init__(self):
  51. super().__init__('Море оливок', BasePizza.BASE_PIZZA_PRICE)
  52. self.add_olives()
  53. class PepperoniPizza(BasePizza, PepperoniMixin):
  54. def __init__(self):
  55. super().__init__('Колбасятина', BasePizza.BASE_PIZZA_PRICE)
  56. self.add_pepperoni()
  57. class MushroomOnionBaconPizza(BasePizza, MushroomMixin, OnionMixin, BaconMixin):
  58. def __init__(self):
  59. super().__init__('Грибной пяточок с луком', BasePizza.BASE_PIZZA_PRICE)
  60. self.add_mushrooms()
  61. self.add_onion()
  62. self.add_bacon()
  63. class CountryPizza(BasePizza, HamMixin, PepperMixin, OlivesMixin, PepperoniMixin, MushroomMixin, ChickenMixin):
  64. def __init__(self):
  65. super().__init__('Деревенская пицца', BasePizza.BASE_PIZZA_PRICE)
  66. self.add_ham()
  67. self.add_pepper()
  68. self.add_olives()
  69. self.add_pepperoni()
  70. self.add_mushrooms()
  71. self.add_chicken()
  72. # --------------------------------------------------
  73. def main():
  74. pass
  75. if __name__ == '__main__':
  76. main()