Phase: 5. OOP | Estimated time: 3 hours | Milestone Project: Yes
- All modules 041-049 (Phase 5: OOP)
By the end of this module, you will be able to:
- Design and implement a multi-class OOP system
- Use inheritance to model specialized behavior
- Demonstrate encapsulation with private/protected attributes
- Use dunder methods (
__str__,__repr__,__len__) for integration - Apply polymorphism and duck typing
- Optionally use ABCs for interface contracts
This milestone project ties together everything from Phase 5: classes, attributes, methods, constructors, class/instance variables, encapsulation, inheritance, polymorphism, dunder methods, and abstract base classes. You'll build a complete library management system demonstrating professional OOP design.
Build a Library Management System with three core classes: Book, Member, and Library. The system should handle adding/borrowing/returning books, tracking members, and enforcing borrowing limits.
class Book:
"""Represents a book in the library."""
def __init__(self, title, author, isbn, copies=1):
self.title = title
self.author = author
self.isbn = isbn
self._copies = copies
self._available = copies
# Properties, dunder methods, and methodsclass Member:
"""Represents a library member."""
def __init__(self, name, member_id):
self.name = name
self.member_id = member_id
self.borrowed_books = []
def borrow_book(self, book):
"""Borrow a book from the library."""
def return_book(self, book):
"""Return a borrowed book."""class Library:
"""Manages the collection of books and members."""
def __init__(self, name):
self.name = name
self.books = {}
self.members = {}
def add_book(self, book):
"""Add a book to the library."""
def add_member(self, member):
"""Register a member."""
def borrow_book(self, member_id, isbn):
"""Allow a member to borrow a book."""
def return_book(self, member_id, isbn):
"""Process a book return."""
def list_books(self):
"""List all books in the library."""
def list_members(self):
"""List all registered members."""StudentMember: Can borrow up to 3 books, 14-day loan periodTeacherMember: Can borrow up to 10 books, 30-day loan period
- Add books with title, author, ISBN, and copy count
- Register members (Student or Teacher)
- Borrow a book (decrease available copies, add to member's list)
- Return a book (increase available copies, remove from member's list)
- List all books with availability
- List all members with their borrowed books
- Enforce borrowing limits per member type
- Prevent borrowing unavailable books
- Use
@propertyfor controlled attribute access - Implement
__str__and__repr__on all classes
- Add a
search_books(title)orsearch_by_author(author)method - Add a
get_borrowing_history(member_id)method - Add overdue tracking with fines
- Add a
@dataclassversion ofBook - Add
Reservablemixin for reserving books
- OOP organizes complex systems into interacting classes.
- Inheritance models specialized behavior (Student vs Teacher members).
- Encapsulation protects internal state (available copies, borrowed lists).
- Dunder methods make objects work with Python built-ins.
- A well-designed class hierarchy is reusable and extensible.
Continue to Module 051 (Phase 6: Advanced OOP).
See project/README.md for detailed instructions. The project/starter_code.py file contains a skeleton to complete. A full solution is in project/solution/library_system.py.