-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract_factory.py
93 lines (64 loc) · 2.19 KB
/
abstract_factory.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from abc import ABC
from enum import Enum
class Style(Enum):
"""Style Enum Class
This can be an ABC-based class, but for sake of simplicity, this is an Enum.
"""
victorian = "victorian"
modern = "modern"
art_deco = "art_deco"
class Furniture(ABC):
"""Abstract Furniture class"""
def __init__(self, style: Style) -> None:
self.style = style
class Chair(Furniture):
"""Chair Class"""
pass
class Table(Furniture):
"""Table Class"""
pass
class Sofa(Furniture):
"""Sofa Class"""
pass
class AbstractFurnitureFactory(ABC):
"""Abstract Furniture Factory class"""
def __init__(self, style: Style) -> None:
self.style = style
def make_chair(self) -> Chair:
"""Chair creation method """
print(f'{self.style} style Chair created')
return Chair(self.style)
def make_table(self) -> Table:
"""Table creation method """
print(f'{self.style} style Table created')
return Table(self.style)
def make_sofa(self) -> Sofa:
"""Sofa creation method """
print(f'{self.style} style Sofa created')
return Sofa(self.style)
class VictorianFurnitureFactory(AbstractFurnitureFactory):
"""Victorian Furniture Factory class"""
def __init__(self) -> None:
super().__init__(Style.victorian)
class ModernFurnitureFactory(AbstractFurnitureFactory):
"""Modern Furniture Factory class"""
def __init__(self) -> None:
super().__init__(Style.modern)
class ArtDecoFurnitureFactory(AbstractFurnitureFactory):
"""ArtDeco Furniture Factory class"""
def __init__(self) -> None:
super().__init__(Style.art_deco)
class AbstractFactory:
"""Abstract factory"""
@staticmethod
def new(style: str) -> AbstractFurnitureFactory:
match style:
case Style.victorian.value:
return VictorianFurnitureFactory()
case Style.modern.value:
return ModernFurnitureFactory()
case Style.art_deco.value:
return ArtDecoFurnitureFactory()
case _:
raise Exception(
f'No factory that produces furniture in the {style} style')