Parcourir la source

Merge branch 'arovit-master'

Sakis Kasampalis il y a 11 ans
Parent
commit
39c74d0638
2 fichiers modifiés avec 27 ajouts et 15 suppressions
  1. 18 6
      3-tier.py
  2. 9 9
      abstract_factory.py

+ 18 - 6
3-tier.py

@@ -3,6 +3,7 @@
 
 
 
 
 class Data(object):
 class Data(object):
+    """ Data Store Class """
 
 
     products = {
     products = {
         'milk': {'price': 1.50, 'quantity': 10},
         'milk': {'price': 1.50, 'quantity': 10},
@@ -10,20 +11,26 @@ class Data(object):
         'cheese': {'price': 2.00, 'quantity': 10}
         'cheese': {'price': 2.00, 'quantity': 10}
     }
     }
 
 
+    def __get__(self, obj, klas):
+        print ("(Fetching from Data Store)")
+        return {'products': self.products}
+
 
 
 class BusinessLogic(object):
 class BusinessLogic(object):
 
 
-    def __init__(self):
-        self.data = Data()
+    """ Business logic holding data store instances """
+
+    data = Data()
 
 
     def product_list(self):
     def product_list(self):
-        return self.data.products.keys()
+        return self.data['products'].keys()
 
 
     def product_information(self, product):
     def product_information(self, product):
-        return self.data.products.get(product, None)
+        return self.data['products'].get(product, None)
 
 
 
 
 class Ui(object):
 class Ui(object):
+    """ UI interaction class """
 
 
     def __init__(self):
     def __init__(self):
         self.business_logic = BusinessLogic()
         self.business_logic = BusinessLogic()
@@ -59,14 +66,19 @@ if __name__ == '__main__':
 
 
 ### OUTPUT ###
 ### OUTPUT ###
 # PRODUCT LIST:
 # PRODUCT LIST:
+# (Fetching from Data Store)
+# cheese
 # eggs
 # eggs
 # milk
 # milk
-# cheese
-#
+# 
+# (Fetching from Data Store)
 # PRODUCT INFORMATION:
 # PRODUCT INFORMATION:
 # Name: Cheese, Price: 2.00, Quantity: 10
 # Name: Cheese, Price: 2.00, Quantity: 10
+# (Fetching from Data Store)
 # PRODUCT INFORMATION:
 # PRODUCT INFORMATION:
 # Name: Eggs, Price: 0.20, Quantity: 100
 # Name: Eggs, Price: 0.20, Quantity: 100
+# (Fetching from Data Store)
 # PRODUCT INFORMATION:
 # PRODUCT INFORMATION:
 # Name: Milk, Price: 1.50, Quantity: 10
 # Name: Milk, Price: 1.50, Quantity: 10
+# (Fetching from Data Store)
 # That product "arepas" does not exist in the records
 # That product "arepas" does not exist in the records

+ 9 - 9
abstract_factory.py

@@ -23,9 +23,9 @@ class PetShop:
         abstract factory"""
         abstract factory"""
 
 
         pet = self.pet_factory.get_pet()
         pet = self.pet_factory.get_pet()
-        print("This is a lovely {}".format(pet))
+        print("We have a lovely {}".format(pet))
         print("It says {}".format(pet.speak()))
         print("It says {}".format(pet.speak()))
-        print("It eats {}".format(self.pet_factory.get_food()))
+        print("We also have {}".format(self.pet_factory.get_food()))
 
 
 
 
 # Stuff that our factory makes
 # Stuff that our factory makes
@@ -83,15 +83,15 @@ if __name__ == "__main__":
         print("=" * 20)
         print("=" * 20)
 
 
 ### OUTPUT ###
 ### OUTPUT ###
-# This is a lovely Dog
+# We have a lovely Dog
 # It says woof
 # It says woof
-# It eats dog food
+# We also have dog food
 # ====================
 # ====================
-# This is a lovely Cat
-# It says meow
-# It eats cat food
+# We have a lovely Dog
+# It says woof
+# We also have dog food
 # ====================
 # ====================
-# This is a lovely Dog
+# We have a lovely Dog
 # It says woof
 # It says woof
-# It eats dog food
+# We also have dog food
 # ====================
 # ====================