-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstractFactory_final.py
More file actions
executable file
·51 lines (32 loc) · 1.06 KB
/
abstractFactory_final.py
File metadata and controls
executable file
·51 lines (32 loc) · 1.06 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
class Dog:
"""One of the objects to be returned"""
def speak(self):
return "Woof!"
def __str__(self):
return "Dog"
class DogFactory:
"""Concrete Factory"""
def get_pet(self):
"""Returns a Dog object"""
return Dog()
def get_food(self):
"""Returns a Dog Food object"""
return "Dog Food!"
class PetStore:
""" PetStore houses our Abstract Factory """
def __init__(self, pet_factory=None):
""" pet_factory is our Abstract Factory """
self._pet_factory = pet_factory
def show_pet(self):
""" Utility method to display the details of the objects retured by the DogFactory """
pet = self._pet_factory.get_pet()
pet_food = self._pet_factory.get_food()
print("Our pet is '{}'!".format(pet))
print("Our pet says hello by '{}'".format(pet.speak()))
print("Its food is '{}'!".format(pet_food))
#Create a Concrete Factory
factory = DogFactory()
#Create a pet store housing our Abstract Factory
shop = PetStore(factory)
#Invoke the utility method to show the details of our pet
shop.show_pet()