-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhouse.py
108 lines (81 loc) · 2.05 KB
/
house.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""house trade system
using command design patterns"""
from abc import ABC, abstractmethod
from typing import List
class Order(ABC):
"""The basic of home ordering classes
"""
@abstractmethod
def execute(self):
"""execute command or commands
"""
@abstractmethod
def describe(self):
"""order description
"""
class HouseTrade:
"""Buying and selling a home
"""
@staticmethod
def buy():
"""The buyer buys the house
"""
print("You are buying this house.")
@staticmethod
def sell():
"""The seller is selling the house
"""
print("You are selling this house")
class BuyHouse(Order):
"""buy a house
"""
def __init__(self, house: HouseTrade):
self.house = house
def execute(self):
"""execute buy command
"""
self.house.buy()
def describe(self):
print("cheap and amazing house")
class SellHouse(Order):
"""sell a house
"""
def __init__(self, house: HouseTrade):
self.house = house
def execute(self):
"""execute sell command
"""
self.house.sell()
def describe(self):
print("big and beautiful house")
class Agent:
"""order management
"""
def __init__(self):
self.__order_queue: List[Order] = []
def request_order(self, order: Order):
"""request a order
Args:
order (Order): the order
"""
self.__order_queue.append(order)
def place_orders(self):
"""place all orders
"""
for order in self.__order_queue:
order.execute()
if __name__ == "__main__":
house1 = HouseTrade()
house2 = HouseTrade()
house3 = HouseTrade()
buy_house = BuyHouse(house1)
sell_house = SellHouse(house2)
house3_order = BuyHouse(house3)
# take order
agent = Agent()
agent.request_order(buy_house)
agent.request_order(sell_house)
agent.request_order(house3_order)
# place orders
agent.place_orders()
print()