-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjustment to UI and Business logic for injecting dependencies
- Loading branch information
Showing
1 changed file
with
8 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
yarikoptic
Contributor
|
||
|
||
def product_list(self): | ||
return self.data['products'].keys() | ||
|
@@ -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:') | ||
|
@@ -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') | ||
|
@@ -69,7 +72,7 @@ def main(): | |
# cheese | ||
# eggs | ||
# milk | ||
# | ||
# | ||
# (Fetching from Data Store) | ||
# PRODUCT INFORMATION: | ||
# Name: Cheese, Price: 2.00, Quantity: 10 | ||
|
Doesn't introducing this brake Data as a descriptor usage?
Wouldn't
BusinessLogic.data = data
solve this?