Skip to content

Commit 69b507b

Browse files
committed
Adjustment to UI and Business logic for injecting dependencies
1 parent c828edd commit 69b507b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

3-tier.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def __get__(self, obj, klas):
1919
class BusinessLogic(object):
2020
""" Business logic holding data store instances """
2121

22-
data = Data()
22+
def __init__(self, data):
23+
self.data = data
2324

2425
def product_list(self):
2526
return self.data['products'].keys()
@@ -31,8 +32,8 @@ def product_information(self, product):
3132
class Ui(object):
3233
""" UI interaction class """
3334

34-
def __init__(self):
35-
self.business_logic = BusinessLogic()
35+
def __init__(self, logic):
36+
self.business_logic = logic
3637

3738
def get_product_list(self):
3839
print('PRODUCT LIST:')
@@ -53,7 +54,9 @@ def get_product_information(self, product):
5354

5455

5556
def main():
56-
ui = Ui()
57+
data = Data()
58+
logic = BusinessLogic(data)
59+
ui = Ui(logic)
5760
ui.get_product_list()
5861
ui.get_product_information('cheese')
5962
ui.get_product_information('eggs')
@@ -69,7 +72,7 @@ def main():
6972
# cheese
7073
# eggs
7174
# milk
72-
#
75+
#
7376
# (Fetching from Data Store)
7477
# PRODUCT INFORMATION:
7578
# Name: Cheese, Price: 2.00, Quantity: 10

0 commit comments

Comments
 (0)