|
3 | 3 |
|
4 | 4 |
|
5 | 5 | class Data(object): |
| 6 | + """ Data Store Class """ |
6 | 7 |
|
7 | 8 | products = { |
8 | 9 | 'milk': {'price': 1.50, 'quantity': 10}, |
9 | 10 | 'eggs': {'price': 0.20, 'quantity': 100}, |
10 | 11 | 'cheese': {'price': 2.00, 'quantity': 10} |
11 | 12 | } |
12 | 13 |
|
| 14 | + def __get__(self, obj, klas): |
| 15 | + print "(Fetching from Data Store)" |
| 16 | + return {'products': self.products} |
| 17 | + |
13 | 18 |
|
14 | 19 | class BusinessLogic(object): |
15 | 20 |
|
16 | | - def __init__(self): |
17 | | - self.data = Data() |
| 21 | + """ Business logic holding data store instances """ |
| 22 | + |
| 23 | + data = Data() |
18 | 24 |
|
19 | 25 | def product_list(self): |
20 | | - return self.data.products.keys() |
| 26 | + return self.data['products'].keys() |
21 | 27 |
|
22 | 28 | def product_information(self, product): |
23 | | - return self.data.products.get(product, None) |
| 29 | + return self.data['products'].get(product, None) |
24 | 30 |
|
25 | 31 |
|
26 | 32 | class Ui(object): |
| 33 | + """ UI interaction class """ |
27 | 34 |
|
28 | 35 | def __init__(self): |
29 | 36 | self.business_logic = BusinessLogic() |
@@ -59,14 +66,19 @@ def main(): |
59 | 66 |
|
60 | 67 | ### OUTPUT ### |
61 | 68 | # PRODUCT LIST: |
| 69 | +# (Fetching from Data Store) |
| 70 | +# cheese |
62 | 71 | # eggs |
63 | 72 | # milk |
64 | | -# cheese |
65 | | -# |
| 73 | +# |
| 74 | +# (Fetching from Data Store) |
66 | 75 | # PRODUCT INFORMATION: |
67 | 76 | # Name: Cheese, Price: 2.00, Quantity: 10 |
| 77 | +# (Fetching from Data Store) |
68 | 78 | # PRODUCT INFORMATION: |
69 | 79 | # Name: Eggs, Price: 0.20, Quantity: 100 |
| 80 | +# (Fetching from Data Store) |
70 | 81 | # PRODUCT INFORMATION: |
71 | 82 | # Name: Milk, Price: 1.50, Quantity: 10 |
| 83 | +# (Fetching from Data Store) |
72 | 84 | # That product "arepas" does not exist in the records |
0 commit comments