-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesign_pattern_strategy.py
More file actions
35 lines (25 loc) · 946 Bytes
/
Copy pathdesign_pattern_strategy.py
File metadata and controls
35 lines (25 loc) · 946 Bytes
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
class AUsefulThing(object):
def __init__(self, aStrategicAlternative):
super(AUsefulThing, self).__init__()
self.howToDoX = aStrategicAlternative
def doX(self, someArg):
self. howToDoX.theAPImethod(someArg, self)
class StrategicAlternative(object):
pass
class AlternativeOne(StrategicAlternative):
def __init__(self):
super(AlternativeOne, self).__init__()
def theAPImethod(self, someArg, theUsefulThing):
print("an implementation through ", theUsefulThing.__class__.__name__)
pass # an implementation
class AlternativeTwo(StrategicAlternative):
def theAPImethod(self, someArg, theUsefulThing):
print("another implementation",theUsefulThing)
pass # another implementation
if __name__ == '__main__':
val = AlternativeTwo
t = AUsefulThing(val())
t.doX('arg')
val = AlternativeOne
one = AUsefulThing(val())
one.doX('arg_one')