-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathabstract_factory_concept.py
39 lines (30 loc) · 1.04 KB
/
abstract_factory_concept.py
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
# pylint: disable=too-few-public-methods
"Abstract Factory Concept Sample Code"
from abc import ABCMeta, abstractmethod
from factory_a import FactoryA
from factory_b import FactoryB
class IAbstractFactory(metaclass=ABCMeta):
"Abstract Factory Interface"
@staticmethod
@abstractmethod
def create_object(factory):
"The static Abstract factory interface method"
class AbstractFactory(IAbstractFactory):
"The Abstract Factory Concrete Class"
@staticmethod
def create_object(factory):
"Static get_factory method"
try:
if factory in ['aa', 'ab', 'ac']:
return FactoryA.create_object(factory[1])
if factory in ['ba', 'bb', 'bc']:
return FactoryB.create_object(factory[1])
raise Exception('No Factory Found')
except Exception as _e:
print(_e)
return None
# The Client
PRODUCT = AbstractFactory.create_object('ab')
print(f"{PRODUCT.__class__}")
PRODUCT = AbstractFactory.create_object('bc')
print(f"{PRODUCT.__class__}")