Skip to content

Day 3 : Library Management + Classroom Attendance System

🟢 Day 3 — Multiple Objects & Object Interaction

🎯 Day 3 Objective

By the end of Day 3, the candidate should be able to:
Manage multiple objects at once
Store and retrieve objects using IDs
Write manager / controller classes
Handle interactions between objects
Implement problems where logic spans more than one class
Today is about coordination, not just state.

1️⃣ Teaching Script — What to Say

Start with This Reality

“In real systems, nothing works alone.”
Examples:
A library has many books
A classroom has many students
A game has many players
A booking system has many seats
Machine coding rounds almost always involve ​one manager class controlling many objects.

2️⃣ Core Idea of Day 3

One object manages many objects.
This manager:
Stores objects (list / dict)
Finds objects by ID
Calls methods on them
Enforces rules
This is usually where:
Bad design
Confusion
Bugs appear

3️⃣ Small Code to Understand (Very Important)

Example — Student Manager

class Student:
def __init__(self, student_id: int, name: str):
self.student_id = student_id
self.name = name


class StudentManager:
def __init__(self):
self.students = {}

def add_student(self, student: Student):
self.students[student.student_id] = student

def get_student(self, student_id: int):
return self.students.get(student_id)

Key Observations

StudentManager owns the collection
Student does NOT know about manager
IDs are used to fetch objects
.get() avoids crashes
🧠 This pattern appears everywhere in interviews.

4️⃣ Mandatory Warm-up Practice

Task

Implement these classes:
Class: User
- user_id (int)
- name (str)

Class: UserRegistry
Methods:
- add_user(user)
- get_user(user_id) → User or None
Rules:
Store users using dictionary
Do not print
Do not validate duplicates yet
👉 This is just to warm up object storage thinking.

5️⃣ Machine Coding Rules (Day 3 Rules)

Read carefully:
Manager class owns collections
Objects should not access manager
Use IDs for lookup
Return False / None for invalid operations
Do not guess missing behavior

6️⃣ Main Problem 1 — Library Management (Classic Interview Problem)

Problem Statement

You are building a library system.
A library contains multiple books
Each book can be borrowed by only one user at a time

Class Definitions (DO NOT MODIFY)

class Book:
def __init__(self, book_id: int, title: str):
pass

def borrow(self) -> bool:
pass

def return_book(self) -> bool:
pass

def is_borrowed(self) -> bool:
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.