-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.py
More file actions
executable file
·58 lines (42 loc) · 1.41 KB
/
Data.py
File metadata and controls
executable file
·58 lines (42 loc) · 1.41 KB
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
#!/usr/bin/env python3
import class_Ui
def main():
ui = Ui()
'''
Separates presentation, application processing, and data management functions.
'''
class Data(object):
''' Data Store Class '''
products = {
'milk': {'price': 1.50, 'quantity': 10},
'eggs': {'price': 0.20, 'quantity': 100},
'cheese': {'price': 2.00, 'quantity': 10},
}
def __get__(self, obj, klas):
print('(Fetching from Data Store)')
return {'products': self.products}
class BusinessLogic(object):
''' Business logic holding data store instances '''
data = Data()
def product_list(self):
return self.data['products'].keys()
def product_information(self, product):
return self.data['products'].get(product, None)
class Ui(object):
''' UI interaction class '''
def __init__(self):
self.business_logic = BusinessLogic()
def get_product_list(self):
print('PRODUCT LIST:')
for product in self.business_logic.product_list():
print(product)
print('')
def get_product_information(self, product):
product_info = self.business_logic.product_information(product)
if product_info:
print('PRODUCT INFORMATION:')
print('Name: {0}, Price: {1:.2f}, Quantity: {2:}'.format(product.title(), product_info.get('price', 0), product_info.get('quantity', 0)))
else:
print('That product {0} does not exist in the records'.format(product))
if __name__ == '__main__':
main()