forked from Sean-Bradley/Design-Patterns-In-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridge_concept.py
60 lines (44 loc) · 1.46 KB
/
bridge_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# pylint: disable=too-few-public-methods
# pylint: disable=arguments-differ
"Bridge Pattern Concept Sample Code"
from abc import ABCMeta, abstractmethod
class IAbstraction(metaclass=ABCMeta):
"The Abstraction Interface"
@staticmethod
@abstractmethod
def method(*args):
"The method handle"
class RefinedAbstractionA(IAbstraction):
"A Refined Abstraction"
def __init__(self, implementer):
self.implementer = implementer()
def method(self, *args):
self.implementer.method(*args)
class RefinedAbstractionB(IAbstraction):
"A Refined Abstraction"
def __init__(self, implementer):
self.implementer = implementer()
def method(self, *args):
self.implementer.method(*args)
class IImplementer(metaclass=ABCMeta):
"The Implementer Interface"
@staticmethod
@abstractmethod
def method(*args: tuple) -> None:
"The method implementation"
class ConcreteImplementerA(IImplementer):
"A Concrete Implementer"
@staticmethod
def method(*args: tuple) -> None:
print(args)
class ConcreteImplementerB(IImplementer):
"A Concrete Implementer"
@staticmethod
def method(*args: tuple) -> None:
for arg in args:
print(arg)
# The Client
REFINED_ABSTRACTION_A = RefinedAbstractionA(ConcreteImplementerA)
REFINED_ABSTRACTION_A.method('a', 'b', 'c')
REFINED_ABSTRACTION_B = RefinedAbstractionB(ConcreteImplementerB)
REFINED_ABSTRACTION_B.method('a', 'b', 'c')