These are the notes for Low-Level Design (LLD) episode 20: object-oriented analysis. Someone hands you one vague sentence, "build a movie ticket booking system", and you have to turn it into the right classes. If you start coding at once, you get a real bug (one seat sold twice) and a design that can't even say which show a ticket is for. This episode is the method that prevents that: clarifying questions, functional and non-functional requirements, written assumptions, use cases, noun-verb analysis, candidate classes, CRC cards, the domain model, aggregates, class API design and sketching the class diagram. Every program was actually run with javac Main.java && java -cp . Main (Java 21). Outputs and error messages are real.
1. The real-life problem: the tailor who didn't measure
A customer calls a tailor: "make me one kurta". The tailor is fast and cuts the cloth at once: no measurements, no questions about length, collar or occasion. The kurta comes out too short with the wrong collar, and cut cloth can't be uncut. A good tailor measures first, asks questions, writes everything on a slip, and only then cuts.
Developers make the first tailor's mistake every day: they start writing classes from a one-line prompt.
2. The problem in code: coding straight from the prompt
A single-screen cinema in Indore asks for "a movie ticket booking system". We start coding immediately: a ticket has a name and a seat, the cinema keeps a list of tickets.
import java.util.*;
class Ticket { // prompt: "build a movie ticket booking system"
String name, seat;
Ticket(String name, String seat) { this.name = name; this.seat = seat; }
}
class Cinema {
List<Ticket> tickets = new ArrayList<>();
void book(String name, String seat) { tickets.add(new Ticket(name, seat)); }
}
public class Main {
public static void main(String[] args) {
Cinema c = new Cinema();
c.book("Ravi", "C5");
c.book("Priya", "C5"); // same seat, same evening
for (Ticket t : c.tickets) System.out.println(t.name + " -> seat " + t.seat);
System.out.println("tickets sold: " + c.tickets.size());
}
}
Ravi -> seat C5
Priya -> seat C5
tickets sold: 2
One chair, two tickets. And it gets worse: the cinema also has a 9 PM show. Change Priya's line to c.book("Priya", "C5", "9 PM");:
Main.java:15: error: method book in class Cinema cannot be applied to given types;
c.book("Priya", "C5", "9 PM"); // the 9 PM show?
^
required: String,String
found: String,String,String
reason: actual and formal argument lists differ in length
1 error
The design doesn't even know that shows exist.
Why it failed, in one line: we never asked a single question. Can a seat be sold twice? Which show? What if two people click at the same moment?
3. Object-oriented analysis
Object-oriented analysis (OOA) means studying the problem before designing the code: what the system must do, which real-world things are involved, and what each thing is responsible for.
| Analysis | Design | |
|---|---|---|
| Question | What are we building? | How do we build it? |
| Output | requirements, use cases, domain model | classes, methods, diagrams, code |
| Tailor | measurements on a slip | the cutting pattern |
The steps, in order, are the rest of these notes.
4. Clarifying questions
Clarifying questions are questions you ask to remove the guesses from a vague request. Real life: a caterer taking a wedding order asks "How many guests? Veg only?" before quoting.
For the cinema:
| Question | Owner's answer |
|---|---|
| How many screens? | One screen, 4 shows a day |
| Can people book many seats at once? | Yes, up to 6 |
| Can people cancel? | Yes, before the show starts |
| How are prices set? | One price per show |
| Online payment? | Not now; pay at the counter |
Good questions cover four areas:
- Scope: what's in and what's out (payments? food orders?).
- Rules: what must never happen (a seat sold twice).
- Scale: how big (one screen or 500 cinemas? 10 users or 10 lakh?).
- Failures: what happens when something goes wrong (seat taken, show cancelled).
In an interview, spend the first ~5 minutes here. Interviewers deliberately give vague prompts to see whether you ask.
5. Functional and non-functional requirements
A requirement is a written statement of something the system must satisfy.
- A functional requirement says what the system does: a feature or behaviour. Caterer: "paneer, dal, 300 plates".
- A non-functional requirement says how well the system does it: speed, safety, reliability, scale, security. Caterer: "served hot, within 30 minutes".
For the cinema:
| ID | Requirement | Kind |
|---|---|---|
| F1 | A customer sees shows and their free seats | functional |
| F2 | A customer books 1 to 6 free seats for a show | functional |
| F3 | A customer cancels a booking before the show | functional |
| N1 | A seat is never sold twice, even when two people book at the same moment | non-functional (correctness under concurrency) |
| N2 | A booking answers in under 1 second | non-functional (performance) |
Concurrency means several things happening at the same time, such as two customers clicking "book" in the same second. N1 is where our first attempt failed.
Quick test: if you can demo it with a button, it's functional. If you measure it with a stopwatch, a load test or a rule that must always hold, it's non-functional.
6. Assumptions
An assumption is a decision you made yourself because nobody told you, written down so the other side can correct it. The caterer writes "sweets: gulab jamun, unless you say otherwise" on the slip.
- A1: Payment happens outside the system (at the counter).
- A2: Every seat in a show has the same price.
A silent guess becomes a bug later. A written assumption becomes a 10-second correction today.
7. Use cases
Real life: an ATM's menu (withdraw, balance, mini statement). Each button is one goal.
- An actor is anyone (a person or another system) who uses the system to get something done: the customer, the cinema manager, a payment gateway.
- A use case is one goal of one actor, written as numbered steps.
- The main flow is the normal path; an alternate flow is what happens when something goes wrong.
Use case: Book seats (actor: Customer)
- Customer picks a show.
- System shows the free seats.
- Customer picks seats; system books them and returns a booking ID.
Alternate flow 3a: a chosen seat is already taken, so the system refuses and the customer picks again.
Other use cases: Browse shows (customer), Cancel booking (customer), Add show (manager).
Episode 19 drew these as a use-case diagram (stick figures and ovals). Here we write the steps; the steps reveal the rules (3a is exactly our bug).
8. Noun-verb analysis and candidate classes
Real life: in a recipe, the nouns are the things (onion, tomato, kadhai) and the verbs are the actions (chop, fry, stir).
Noun-verb analysis means underlining the nouns and verbs in the requirement text: nouns become candidate classes, verbs become candidate responsibilities (methods).
Requirement text, in short sentences:
A customer picks a show of a movie.
The customer books free seats for the show.
Each booking has an ID and a price.
A customer can cancel a booking.
- Nouns: customer, show, movie, seat, booking, ID, price
- Verbs: pick, book, cancel
A candidate class is a possible class that still has to earn its place. Filter the list:
| Noun | Decision | Why |
|---|---|---|
| Customer, Movie, Show, Seat, Booking | keep | real things with their own data and behaviour |
| ID, price | attribute | a single value that describes something else (a field of Booking/Show) |
| ticket | duplicate | means the same as booking; keep one name |
| cinema, system | drop (for now) | the whole app, not one thing inside it |
Verbs become methods: book(), cancel(), freeSeats(). Notice that Show, the noun our first attempt missed, came out of this step.
9. Identifying responsibilities with CRC cards
Real life: at a big wedding, each relative gets a duty card. "Mama ji: arrange the band and the horse. Works with: the DJ, the caterer."
A CRC card (Class, Responsibilities, Collaborators) is an index card with:
- the class name on top,
- its responsibilities on the left: what it knows and what it does,
- its collaborators on the right: the other classes it needs.
CRC cards were proposed by Ward Cunningham and Kent Beck as a teaching tool, in the paper A Laboratory for Teaching Object-Oriented Thinking (OOPSLA 1989).
Identifying responsibilities means deciding which class knows what and which class does what. A useful rule (often called information expert): give a job to the class that already has the data it needs.
┌──────────────── Show ────────────────┐ ┌─────────────── Booking ──────────────┐
│ RESPONSIBILITIES │ COLLABORATORS │ │ RESPONSIBILITIES │ COLLABORATORS │
│ knows movie + time │ Movie │ │ knows its ID │ Customer │
│ knows free seats │ Seat │ │ knows its seats │ Seat │
│ books seats │ Booking │ │ knows its amount │ │
│ cancels a booking │ Customer │ │ knows its customer │ │
│ never sells twice │ │ │ │ │
└──────────────────────┴───────────────┘ └──────────────────────┴───────────────┘
The show knows which seats are free, so the show books and cancels, and the rule "never sell a seat twice" belongs on its card. A card that's too full means the class should be split; an empty card means it probably isn't a class.
10. The domain model and entities
Real life: the reservation chart at a railway station. A train has coaches, a coach has berths, a passenger holds a berth. No code, just the real things and how they connect.
- A domain is the real-world area your software is about: cinemas, railways, banking.
- A domain model is a picture of the domain's concepts, their key attributes and the links between them, without methods or code details. The customer (cinema owner) should be able to read it.
- An entity is an object known by its identity, not its values: PNR 4521 is the same booking even if the seat changes. Show, Booking and Customer are entities.
- A value object is the opposite: known only by its values, like the seat label
"C5"or an amount of Rs 400.
Movie 1 ──── * Show a show is of one movie; a movie has many shows
Show 1 ──── * Seat a show has many seats
Show 1 ──── * Booking a booking is for one show
Customer 1 ── * Booking a booking is made by one customer
11. Aggregates and invariants
Real life: the old cinema counter keeps one register per show: the seat chart and the bookings together. You don't write in it yourself; you ask the clerk, who checks and writes. "C5 is taken, sorry." If anyone could grab the pen, C5 would get two names again.
- An invariant is a rule that must always be true: "a seat has at most one booking per show".
- An aggregate is a cluster of objects that change together as one unit: a show plus the bookings of its seats.
- The aggregate root is the one object outsiders may touch. Everything inside is reached through it, so it can check every change against the invariants.
The term comes from Domain-Driven Design (DDD), the approach named by Eric Evans in his 2003 book Domain-Driven Design: Tackling Complexity in the Heart of Software.
The show as an aggregate root:
import java.util.*;
class Show { // aggregate root: guards its seats
final String time;
private final Map<String, String> seats = new TreeMap<>(); // seat -> customer
Show(String time, String... seatNos) {
this.time = time;
for (String s : seatNos) seats.put(s, "free");
}
void book(String seat, String customer) {
if (!"free".equals(seats.get(seat)))
throw new IllegalStateException(seat + " is not free for the " + time + " show");
seats.put(seat, customer);
System.out.println(customer + " booked " + seat + " for " + time);
}
}
public class Main {
public static void main(String[] args) {
Show sixPm = new Show("6 PM", "C4", "C5", "C6");
sixPm.book("C5", "Ravi");
sixPm.book("C5", "Priya");
}
}
Ravi booked C5 for 6 PM
Exception in thread "main" java.lang.IllegalStateException: C5 is not free for the 6 PM show
at Show.book(Main.java:12)
at Main.main(Main.java:21)
IllegalStateException is Java's standard exception for "the object's current state doesn't allow this call". The invariant held. Notice also that an unknown seat ("Z9") is refused too, because seats.get("Z9") is null, which isn't "free".
Now try to skip the root and write directly into the seat map (replace the last line of main with sixPm.seats.put("C5", "Priya");):
Main.java:21: error: seats has private access in Show
sixPm.seats.put("C5", "Priya"); // skip the root, write directly
^
1 error
private is the clerk's locked drawer: the only door in is the root's public method.
Note on N1 (concurrency): this single-threaded demo shows where the check lives. In a real multi-user system you'd also make
booksafe for simultaneous calls (for example asynchronizedmethod, or a database unique constraint on show + seat). Because there is exactly one door, there is exactly one place to add that protection.
12. Class API design
Real life: at a chai stall you say "one cutting chai" through the window. You never walk in and touch the stove, the milk or the sugar jar.
A class's API (Application Programming Interface) is the set of public methods other code may call. Class API design means choosing that set:
| Use case | Public method |
|---|---|
| Book seats | Booking book(Customer c, String... seats) |
| Cancel booking | void cancel(Booking b) |
| Browse seats | List<String> freeSeats() |
Rules:
- Name methods after the use cases (
book, notaddToSeatMap). - Fields are private; no setters (a setter is a method that just overwrites a field, like
setSeats(...), which would let callers skip the rules). - Check the rules inside; fail loudly with an exception.
- Return copies (
List.copyOf), never your own internal collection. - Keep it small: every public method is a promise you must keep forever.
13. Sketching the class diagram
Sketching the class diagram means turning the domain model into a rough UML class diagram (episode 18): add visibility, types and the public methods. Rough first (names and key methods), details only where they matter.
┌──────────── «aggregate root» Show ────────────┐
│ - price: int │
│ - free: Set<String> │
├───────────────────────────────────────────────┤
│ + book(c: Customer, seats...): Booking │
│ + cancel(b: Booking): void │
│ + freeSeats(): List<String> │
└───────────────────────────────────────────────┘
Show 1 ◆──── * Booking composition: bookings live and die with their show
Booking * ───▶ 1 «record» Customer association: the customer exists outside the show
Show * ───▶ 1 Movie association
14. The final design, run
Customer and Booking are records (episode 3): small immutable classes that just hold values. Show is the aggregate root: everything private, three public methods.
import java.util.*;
record Customer(String name) {}
record Booking(int id, Customer who, List<String> seats, int amount) {}
class Show { // aggregate root: the only door in
private final int price; private int nextId = 1;
private final Set<String> free = new TreeSet<>();
private final Set<Booking> active = new HashSet<>();
Show(int price, String... seats) { this.price = price; free.addAll(List.of(seats)); }
Booking book(Customer c, String... want) {
List<String> w = List.of(want);
if (!free.containsAll(w)) throw new IllegalStateException(w + " not free");
free.removeAll(w);
Booking b = new Booking(nextId++, c, w, w.size() * price);
active.add(b); return b;
}
void cancel(Booking b) { if (active.remove(b)) free.addAll(b.seats()); }
List<String> freeSeats() { return List.copyOf(free); }
}
public class Main { public static void main(String[] args) {
Show sixPm = new Show(200, "C4", "C5", "C6"); // Monsoon Express, 6 PM
Booking r = sixPm.book(new Customer("Ravi"), "C5", "C6");
System.out.println("Booking " + r.id() + ": Rs " + r.amount() + ", free " + sixPm.freeSeats());
try { sixPm.book(new Customer("Priya"), "C5"); }
catch (IllegalStateException e) { System.out.println("Priya refused: " + e.getMessage()); }
sixPm.cancel(r); System.out.println("After cancel, free " + sixPm.freeSeats());
} }
Booking 1: Rs 400, free [C4]
Priya refused: [C5] not free
After cancel, free [C4, C5, C6]
How the requirements map to code:
| Requirement | Where |
|---|---|
| F1 see free seats | freeSeats() (a copy, sorted by the TreeSet) |
| F2 book seats | book(...) checks all seats first, then changes anything (all-or-nothing) |
| F3 cancel | cancel(...) frees seats only for an active booking, so cancelling twice does nothing |
| N1 never sold twice | the invariant check inside the root; fields private |
| A2 one price per show | price on Show; amount = seats × price |
(The 1-to-6 seat limit from F2 and the movie link are left as practice question 3.)
15. The whole method on one page
- Ask clarifying questions.
- Write functional and non-functional requirements.
- Write your assumptions.
- List use cases: actor, goal, steps, alternate flows.
- Noun-verb analysis → candidate classes; filter them.
- CRC cards → responsibilities and collaborators.
- Domain model, entities, aggregates and their invariants.
- Class API from the use cases, sketch the class diagram, then code.
Common mistakes
| Mistake | Exact message / symptom | Why | Fix |
|---|---|---|---|
| Coding from the one-line prompt | Ravi -> seat C5 / Priya -> seat C5 |
No questions, so no rules | Ask, then write requirements |
No Show class: c.book("Priya", "C5", "9 PM") |
method book in class Cinema cannot be applied to given types; |
A missed noun | Noun-verb analysis on written requirements |
| Rule checked by callers, not the root | seat sold twice whenever one caller forgets | Invariants need one guard | Check inside the aggregate root: IllegalStateException: C5 is not free for the 6 PM show |
sixPm.seats.put("C5", "Priya") |
seats has private access in Show |
Bypassing the root | Call the public API: book() |
| Turning every noun into a class | Price, Id, Ticket and Booking classes |
Attributes and duplicates not filtered | Values → fields; synonyms → one name |
| Public setters on the root | show.setSeats(...) lets anyone skip the check |
API exposes internals | No setters; methods named after use cases |
| Silent assumptions | the owner finds out after launch | Never written down | Write A1, A2... and read them back |
| Mixing analysis and design | arguing about HashMap before knowing the rules |
Jumping to how before what | Finish requirements and use cases first |
Mini project: society gym slot booking
Your housing society wants an app: "members book gym slots". Do the analysis, then code it.
Clarifying questions (answers): slots are 1 hour; each slot holds at most N members (2 in the demo); a member may hold only one slot per day; members can cancel.
Requirements: F1 book a slot, F2 cancel, F3 see occupancy; N1 a slot never exceeds capacity; N2 one slot per member per day. Assumption: A1 slots are fixed per day (6 AM, 7 AM).
Nouns: member, slot, day, flat, gym. Verbs: book, cancel. Candidates: Member (entity), GymDay (aggregate root), slot (a time inside the day). flat → attribute of Member; gym → the whole app.
Aggregate: GymDay with its slots. Both invariants (capacity, one slot per member per day) span all slots of the day, so the day must be the root, not each slot.
import java.util.*;
record Member(String flat, String name) {}
class GymDay { // aggregate root: one day's timetable
private static final int CAPACITY = 2; // small, so the demo hits the limit
private final String date;
private final Map<String, List<Member>> slots = new TreeMap<>(); // "6 AM" -> members
GymDay(String date, String... times) {
this.date = date;
for (String t : times) slots.put(t, new ArrayList<>());
}
void book(Member m, String time) {
List<Member> slot = slots.get(time);
if (slot == null) throw new IllegalArgumentException("no slot at " + time);
if (slot.size() == CAPACITY) throw new IllegalStateException(time + " is full");
for (List<Member> s : slots.values())
if (s.contains(m)) throw new IllegalStateException(m.name() + " already has a slot on " + date);
slot.add(m);
}
void cancel(Member m) { slots.values().forEach(s -> s.remove(m)); }
Map<String, Integer> occupancy() {
Map<String, Integer> view = new TreeMap<>();
slots.forEach((t, s) -> view.put(t, s.size()));
return view;
}
}
public class Main {
static void tryBook(GymDay d, Member m, String time) {
try { d.book(m, time); System.out.println(m.name() + " -> " + time); }
catch (RuntimeException e) { System.out.println(m.name() + " refused: " + e.getMessage()); }
}
public static void main(String[] args) {
GymDay sat = new GymDay("2026-11-07", "6 AM", "7 AM");
Member asha = new Member("A-101", "Asha"), vikram = new Member("B-204", "Vikram");
Member neha = new Member("C-12", "Neha");
tryBook(sat, asha, "6 AM");
tryBook(sat, vikram, "6 AM");
tryBook(sat, neha, "6 AM"); // full
tryBook(sat, asha, "7 AM"); // second slot, same day
tryBook(sat, neha, "8 AM"); // no such slot
sat.cancel(vikram);
tryBook(sat, neha, "6 AM");
System.out.println("occupancy: " + sat.occupancy());
}
}
Asha -> 6 AM
Vikram -> 6 AM
Neha refused: 6 AM is full
Asha refused: Asha already has a slot on 2026-11-07
Neha refused: no slot at 8 AM
Neha -> 6 AM
occupancy: {6 AM=2, 7 AM=0}
IllegalArgumentException means "you passed a bad argument" (a slot that doesn't exist); IllegalStateException means "the object's state doesn't allow this" (the slot is full). occupancy() returns a fresh map, so callers can't change the real slots.
Practice
1. Sort these into functional (F) and non-functional (NF): (a) a user can reset their password; (b) the site stays up 99.9% of the time; (c) a teacher can upload marks; (d) passwords are stored hashed; (e) search results show in under 500 ms.
Answer
(a) F, (b) NF (availability), (c) F, (d) NF (security), (e) NF (performance).
2. Do noun-verb analysis on: "A library member borrows a book copy. Each loan has a due date. A member can return a copy and pay a fine if it is late." List candidate classes, attributes, and methods.
Answer
Nouns: library, member, book, copy, loan, due date, fine. Keep: Member, Book, BookCopy, Loan (Fine can be a class if fines have their own lifecycle, otherwise an amount on Loan). Attributes: due date (Loan), fine amount (Loan). Drop: library (the whole app). Verbs → methods: borrow, returnCopy, payFine. Book vs copy is not a duplicate: a book is the title, a copy is one physical item (an entity with its own ID).
3. Extend the final Show so that F2's limit holds (1 to 6 seats per booking) and the show knows its movie. Which exception fits, and where does the check go?
Answer
Inside book, before anything changes: if (want.length < 1 || want.length > 6) throw new IllegalArgumentException("book 1 to 6 seats");. It's a bad argument, so IllegalArgumentException. Add private final Movie movie; (with record Movie(String title) {}) and take it in the constructor.
4. Write a CRC card for GymDay from the mini project.
Answer
Responsibilities: knows its date and slots; books a member into a slot; enforces capacity; enforces one slot per member per day; cancels; reports occupancy. Collaborators: Member.
5. In a food-delivery app, is the aggregate root for "an order can't have more than 20 items, and its total must equal the sum of its lines" the OrderLine or the Order? Why?
Answer
Order. Both invariants involve all lines together, so only the order can check them. Outsiders add lines through order.addItem(...), never by editing an OrderLine directly.
Quick quiz
Requirements for a food-delivery app:
A. A customer can place an order
B. A customer can track the rider
C. The app shows the menu in under 2 seconds
D. A restaurant can mark a dish sold out
Which one is a non-functional requirement?
Answer
C. A, B and D say what the system does (functional). C says how fast it must do it: a quality, so non-functional.
Interview questions
- What is object-oriented analysis, and how is it different from design? Studying the problem to find what the system must do and which objects are involved (analysis = what), before deciding classes, methods and code (design = how).
- What do you do in the first five minutes of an LLD interview? Ask clarifying questions about scope, rules, scale and failures; write functional and non-functional requirements and assumptions; confirm them with the interviewer.
- Functional vs non-functional requirements? Functional: behaviour (book a seat). Non-functional: qualities (never double-book, respond in < 1 s, 99.9% uptime).
- What is a use case? What's an alternate flow? One goal of one actor, written as steps; an alternate flow is the path when something goes wrong (seat already taken).
- How do you find classes from requirements? Noun-verb analysis: nouns → candidate classes, verbs → methods; then filter out attributes, duplicates and the system itself.
- What is a CRC card? An index card with a class name, its responsibilities and its collaborators, proposed by Ward Cunningham and Kent Beck as a teaching tool.
- What is a domain model? A picture of the problem's concepts, attributes and links without methods; readable by the business person.
- Entity vs value object? An entity is known by identity (booking #1); a value object only by its values (seat "C5", Rs 400).
- What is an aggregate and an aggregate root? A cluster of objects changed as one unit; the root is the only entry point and guards the invariants (from Domain-Driven Design, Eric Evans, 2003).
- How do you design a class's public API? Methods named after use cases, private fields, no setters, rules checked inside, copies returned, as few methods as possible.
- Where does "a seat can't be sold twice" live in your design, and how would you make it safe for concurrency? Inside the aggregate root's
bookmethod; make that method atomic (a lock/synchronized, or a database unique constraint on show + seat).
Glossary
| Term | Meaning, with an example |
|---|---|
| Object-oriented analysis (OOA) | Studying the problem before designing code: what the system must do, which things exist, who is responsible for what. Asking the cinema owner questions before writing Show |
| Analysis vs design | Analysis decides what to build; design decides how. Tailor: measurements vs cutting pattern |
| Requirement | A written statement the system must satisfy. "F2: book 1 to 6 seats" |
| Functional requirement | What the system does: a feature. "A customer cancels a booking" |
| Non-functional requirement | How well it does it: speed, safety, scale, security. "Booking answers in under 1 second" |
| Clarifying questions | Questions that remove guesses from a vague request. "Can people book many seats at once?" |
| Scope | What's in and what's out. "Payments are out of scope" |
| Assumption | A decision you made yourself, written down so it can be corrected. "A1: payment happens at the counter" |
| Concurrency | Several things happening at the same time. Two customers clicking "book" in the same second |
| Actor | A person or system that uses the system for a goal. Customer, manager |
| Use case | One goal of one actor, written as steps. "Book seats" |
| Main flow | The normal steps of a use case. Pick show, pick seats, get booking ID |
| Alternate flow | What happens when something goes wrong. "Seat taken → pick again" |
| Noun-verb analysis | Underlining nouns (candidate classes) and verbs (candidate methods) in requirement text |
| Candidate class | A possible class from a noun, kept only if it has its own data and behaviour. Show (kept), price (became a field) |
| Attribute | A field: a value describing an object. price of a show |
| Responsibility | Something a class knows or does. Show "books seats" |
| Identifying responsibilities | Deciding which class knows what and does what; give the job to the class that has the data |
| Information expert | The rule "give a responsibility to the class with the information to fulfil it" |
| Collaborator | Another class a class needs to do its job. Show collaborates with Booking |
| CRC card | Class-Responsibilities-Collaborators index card (Cunningham and Beck, OOPSLA 1989) |
| Domain | The real-world area the software is about. Cinema ticketing |
| Domain model | A picture of the domain's concepts, attributes and links, without methods. Movie, Show, Seat, Booking, Customer |
| Entity | An object known by its identity, not its values. Booking #1, PNR 4521 |
| Value object | An object known only by its values. Seat label "C5", Rs 400 |
| Invariant | A rule that must always be true. "A seat has at most one booking per show" |
| Aggregate | A cluster of objects changed together as one unit. A show and its seat bookings |
| Aggregate root | The only object of an aggregate outsiders may touch; it guards the invariants. Show |
| Domain-Driven Design (DDD) | A design approach named by Eric Evans (2003 book) that models software around the domain; source of entities, value objects and aggregates |
| API | Application Programming Interface: the public methods others may call. book, cancel, freeSeats |
| Class API design | Choosing a class's public methods: named after use cases, small, fields hidden |
| Setter | A method that just overwrites a field (setSeats); avoided on aggregate roots |
| Sketching the class diagram | Turning the domain model into a rough UML class diagram with visibility, types and public methods |
| Record | A compact Java class that just holds immutable values. record Customer(String name) {} |
IllegalStateException |
Thrown when the object's current state doesn't allow the call. "C5 is not free for the 6 PM show" |
IllegalArgumentException |
Thrown when an argument is invalid. "no slot at 8 AM" |
TreeSet / TreeMap |
Sorted set / map; keeps seats in order C4, C5, C6 |
List.copyOf |
Returns an unmodifiable copy of a list, so callers can't change your internals |
Summary
- Object-oriented analysis decides what to build before how: coding from a one-line prompt sold seat C5 twice.
- Ask clarifying questions (scope, rules, scale, failures); write functional and non-functional requirements and assumptions.
- Use cases: one goal of one actor, main and alternate flows; alternate flows reveal the rules.
- Noun-verb analysis gives candidate classes and methods; filter out attributes, duplicates and the system.
- CRC cards identify responsibilities and collaborators; give each job to the class with the data.
- The domain model connects the concepts; entities have identity.
- An aggregate root guards the invariants:
IllegalStateException: C5 is not free for the 6 PM show, andseats has private access in Showblocks the back door. - Class API: small, named after use cases, private fields, no setters, return copies. Then sketch the class diagram and code.
Next episode: Design patterns: what they are and how to learn them.