File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ # Factory Design Pattern
2+
3+ The Factory Pattern is a creational pattern that defines an Interface for creating an object and defers instantiation until runtime.
4+
5+ Used when you don't know how many or what type of objects will be needed until or during runtime
6+
7+ ![ Factory Pattern Overview] ( factory_pattern.png )
8+
9+ The Factory Pattern in the context of a Chair Factory
10+ ![ Factory Pattern In Context] ( factory_pattern_chair.png )
11+
12+ ``` python
13+ class ChairFactory :
14+ """ Tha Factory Class"""
15+
16+ @ staticmethod
17+ def get_concrete_object (object_type ):
18+ """ A static method to get a concrete object of type class"""
19+ try :
20+ if object_type == " ObjectA" :
21+ return ObjectA()
22+ if object_type == " ObjectB" :
23+ return ObjectB()
24+ if object_type == " ObjectC" :
25+ return ObjectC()
26+ raise AssertionError (" Object Not Found" )
27+ except AssertionError as _e:
28+ print (_e)
29+ return None
30+ ```
31+
32+ Each Object implements the a Common Interface
33+ ``` python
34+ class ObjectA (IObjectType ):
35+ """ The Object Concrete Class which implements the IObjectType interface"""
36+
37+ ...
38+ ```
You can’t perform that action at this time.
0 commit comments