-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlibrary_item.py
More file actions
58 lines (47 loc) · 1.72 KB
/
library_item.py
File metadata and controls
58 lines (47 loc) · 1.72 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
# ------------ library_item.py ------------
from state import Available, Reserved
class LibraryItem:
def __init__(self, item_id, title, author):
self.item_id = item_id
self.title = title
self.author = author
self.borrow_date = None
self.due_date = None
self.state = Available()
@property
def state(self):
return self._state
@state.setter
def state(self, new_state):
self._state = new_state
def checkout(self,user):
if self.state is None:
raise ValueError("Item state not initialized")
self.state.checkout(self,user)
def return_item(self):
self.state.return_item(self)
def reserve(self):
self.state.reserve(self)
class EBook(LibraryItem):
def __init__(self, item_id, title, author, format,genre):
super().__init__(item_id, title, author)
self.format = format
self.genre = genre
self.item_type = "EBook"
class PrintedBook(LibraryItem):
def __init__(self, item_id, title, author, pages, genre):
super().__init__(item_id, title, author)
self.pages = pages
self.genre = genre
self.item_type = "Printed Book"
class ResearchPaper(LibraryItem):
def __init__(self, item_id, title, author):
super().__init__(item_id, title, author)
self.genre = "research paper"
self.state = Reserved()
self.item_type = "Research Paper"
class Audiobook(LibraryItem):
def __init__(self, item_id, title, author, duration):
super().__init__(item_id, title, author)
self.duration = duration # Duration in minutes
self.item_type = "Audio Book"