-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.py
41 lines (28 loc) · 815 Bytes
/
strategy.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
from abc import ABC, abstractmethod
class Context:
def __init__(self, direction, sentence):
self._direction: Direction = direction()
self.sentence = sentence
@property
def direction(self):
return self._direction
@direction.setter
def direction(self, direction):
self._direction = direction
def sorting(self):
return self._direction.direct(self.sentence)
class Direction(ABC):
@abstractmethod
def direct(self, data):
pass
class Right(Direction):
def direct(self, data):
print(data[::-1])
class Left(Direction):
def direct(self, data):
print(data)
if __name__ == '__main__':
text = Context(Right, 'Hello World...')
text.sorting()
text = Context(Left, 'Hello World...')
text.sorting()