Design Pattern Examples
Overview of object-oriented design patterns
visitor_ordervisitor.py
Go to the documentation of this file.
6
7from .visitor_class import Visitor
8
9
15
16
20 def __init__(self, itemsToOrder : list[str]) -> None:
21 self.ItemsToOrder = itemsToOrder
22 self.ItemsReceived = [] # type: list[str]
24
25
31
32
33
43 def _HandleVisitor(self, shop) -> None:
44 if shop:
45 if hasattr(shop, "PlaceOrder") and shop.PlaceOrder(self.ItemsToOrder):
46 if hasattr(shop, "PickupOrder"):
47 shop.PickupOrder(self.ItemsToOrder, self.ItemsReceived)
48 self.ShopNameReceivedFrom = shop.Name
49
50 def VisitBaker(self, shop) -> None:
51 self._HandleVisitor(shop)
52
53 def VisitButcher(self, shop) -> None:
54 self._HandleVisitor(shop)
55
56 def VisitPickleGrocer(self, shop) -> None:
57 self._HandleVisitor(shop)
58
59 def VisitCondimentGrocer(self, shop) -> None:
60 self._HandleVisitor(shop)
61
62 def VisitVegetableGrocer(self, shop) -> None:
63 self._HandleVisitor(shop)
64
65 def VisitMaker(self, shop) -> None:
66 self._HandleVisitor(shop)
67
68 def VisitRestaurant(self, shop) -> None:
69 self._HandleVisitor(shop)
All visitors must implement this base class and then override one or more of the VisitXXX() methods,...
A visitor used for ordering items from various shops.
ItemsReceived
List of items received from an order/pickup process.
None VisitButcher(self, shop)
Let the visitor visit a Visitor_Butcher shop.
None VisitMaker(self, shop)
Let the visitor visit a Visitor_Maker shop.
None VisitPickleGrocer(self, shop)
Let the visitor visit a Visitor_PickleGrocer shop.
None VisitRestaurant(self, shop)
Let the visitor visit a Visitor_Restaurant shop.
None VisitVegetableGrocer(self, shop)
Let the visitor visit a Visitor_VegetableGrocer shop.
None VisitCondimentGrocer(self, shop)
Let the visitor visit a Visitor_CondimentGrocer shop.
ItemsToOrder
Items to be ordered from any shop that sells the item.
None _HandleVisitor(self, shop)
Helper method to handle a visitor, since all visitors are handled in the same way in this collection ...
None VisitBaker(self, shop)
Let the visitor visit a Visitor_Baker shop.