-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstate.py
More file actions
33 lines (26 loc) · 917 Bytes
/
state.py
File metadata and controls
33 lines (26 loc) · 917 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
# ------------ state.py ------------
class State:
def checkout(self, item, user):
pass
def return_item(self, item):
pass
def reserve(self, item):
pass
class Available(State):
def checkout(self, item, user):
print(f"{item.title} checked out by {user.name}")
item.state = CheckedOut()
def reserve(self, item):
print(f"{item.title} reserved")
item.state = Reserved()
class CheckedOut(State):
def return_item(self, item):
print(f"{item.title} returned")
item.state = Available()
class Reserved(State):
def checkout(self, item, user):
if user.role.lower() in ["faculty", "researcher"]:
print(f"Reserved item '{item.title}' checked out by {user.role.capitalize()} {user.name}")
item.state = CheckedOut()
else:
print("Reserved item")