File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ #
2
+ # Python Design Patterns: Bridge
3
+ # Author: Jakub Vojvoda [github.com/JakubVojvoda]
4
+ # 2016
5
+ #
6
+ # Source code is licensed under MIT License
7
+ # (for more details see LICENSE)
8
+ #
9
+
10
+ import sys
11
+
12
+ #
13
+ # Implementor
14
+ # defines the interface for implementation classes
15
+ #
16
+ class Implementor :
17
+ def action (self ):
18
+ pass
19
+
20
+ #
21
+ # Concrete Implementors
22
+ # implement the Implementor interface and define concrete implementations
23
+ #
24
+ class ConcreteImplementorA (Implementor ):
25
+ def action (self ):
26
+ print ("Concrete Implementor A" )
27
+
28
+ class ConcreteImplementorB (Implementor ):
29
+ def action (self ):
30
+ print ("Concrete Implementor B" )
31
+
32
+ #
33
+ # Bridge
34
+ # decouple an abstraction from its implementation
35
+ #
36
+ class Bridge :
37
+ def __init__ (self , implementation ):
38
+ self ._implementor = implementation
39
+
40
+ def operation (self ):
41
+ self ._implementor .action ()
42
+
43
+
44
+ if __name__ == "__main__" :
45
+ bridge = Bridge (ConcreteImplementorA ())
46
+ bridge .operation ()
47
+
48
+ bridge = Bridge (ConcreteImplementorB ())
49
+ bridge .operation ()
You can’t perform that action at this time.
0 commit comments