-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstate.py
More file actions
45 lines (32 loc) · 794 Bytes
/
state.py
File metadata and controls
45 lines (32 loc) · 794 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
36
37
38
39
40
41
42
43
44
45
from abc import ABC, abstractmethod
class VideoEtat(ABC):
@abstractmethod
def action(self):
pass
class EtatLecture(VideoEtat):
def action(self):
print("Video en lecture")
class EtatPause(VideoEtat):
def action(self):
print("Video en pause")
class EtatArret(VideoEtat):
def action(self):
print("Video en arrêt")
class Video:
def __init__(self):
self._etat = EtatArret()
@property
def etat(self):
return self._etat
@etat.setter
def etat(self, valeur):
self._etat = valeur
def action(self):
self._etat.action()
if __name__ == "__main__":
video = Video()
video.action()
video.etat = EtatLecture()
video.action()
video.etat = EtatPause()
video.action()