Skip to content

Commit

Permalink
Adjustment to UI and Business logic for injecting dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
justanr committed Nov 8, 2015
1 parent c828edd commit 69b507b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions 3-tier.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def __get__(self, obj, klas):
class BusinessLogic(object):
""" Business logic holding data store instances """

data = Data()
def __init__(self, data):
self.data = data

This comment has been minimized.

Copy link
@tdaliviu

tdaliviu May 10, 2016

Doesn't introducing this brake Data as a descriptor usage?
Wouldn't BusinessLogic.data = data solve this?

This comment has been minimized.

Copy link
@yarikoptic

yarikoptic May 17, 2016

Contributor

yeap, it did :-/ if binding to the entire class, it kinda ruins the necessity of passing it via constructor, so I have reverted this one in #144 ... upstream might disagree ;) I just wanted to get all the testing to pass first


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

def __init__(self):
self.business_logic = BusinessLogic()
def __init__(self, logic):
self.business_logic = logic

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


def main():
ui = Ui()
data = Data()
logic = BusinessLogic(data)
ui = Ui(logic)
ui.get_product_list()
ui.get_product_information('cheese')
ui.get_product_information('eggs')
Expand All @@ -69,7 +72,7 @@ def main():
# cheese
# eggs
# milk
#
#
# (Fetching from Data Store)
# PRODUCT INFORMATION:
# Name: Cheese, Price: 2.00, Quantity: 10
Expand Down

0 comments on commit 69b507b

Please sign in to comment.