You will design and implement a small library management system using every OOP concept from this course. This is an open-ended project — implement it in your local Python environment and test with pytest.
LibraryItem(ABC) — abstract properties: title, item_id; abstract method: checkout_duration_days.Book, DVD, Magazine — each with appropriate attributes and checkout durations.Member class with @property for name (strip whitespace), email (validate @ present).Library.item_count tracks total items added across all Library instances.Book.__repr__, Book.__eq__ (same ISBN = same book), Book.__lt__ (sort by title).Library acts as a Factory — Library.create_item(kind, **kwargs) returns the right subclass.Start small: get Book and Member working first, then add Library, then the factory and tests.
LibraryItem directly raises TypeErrorBook objects with the same ISBN compare equalBook objects sorts alphabetically by title using sorted()Member rejects an email without @Library.create_item('book', ...) returns a Book instanceFinished early? Add a Reservation system using the Observer pattern — Member subscribes to an item and is notified when it becomes available.
Which OOP concept prevents instantiating LibraryItem directly?
class LibraryItem(ABC) with @abstractmethod stubs forces every concrete subclass to implement those methods.Book.__eq__ based on ISBN means
Book, same ISBN = same book (value equality), even if they're different Python objects.sorted(books) works on a list of Book objects because
__lt__ (and ideally use @functools.total_ordering) to make your objects sortable with sorted() and .sort().Library.create_item() is an example of
Library.create_item('dvd', ...) returns a DVD — the caller doesn't import DVD directly. Easy to extend with new item types.A property that validates email should raise ValueError when
ValueError with a descriptive message so the caller knows exactly what was wrong.