CMD Guide
HomeOO & Low-Level Design

OOD Foundations

Step 1 in the OO & Low-Level Design path · 10 concepts · 0 problems

0 / 10 complete

📘 Learn OOD Foundations from zero

Start from zero. Object-oriented design (OOD) is a way of writing software by bundling data and the behavior that acts on that data into single units called objects. A class is the blueprint; an object is one built thing from that blueprint.

Analogy: a coffee shop. The recipe card for a latte is a class — it lists ingredients (attributes: size, milkType) and steps (methods: brew(), steamMilk()). Each actual latte handed to a customer is an object. The four pillars: Encapsulation (bundle the data with its methods and lock down direct access — the espresso machine exposes a button, not its boiler valves) — Abstraction (model only the essentials, hide the rest — you order "a latte," not "92C water through 18g of grounds") — Inheritance (a FlavoredLatte is-a Latte with extra syrup) — Polymorphism (every drink exposes prepare(), but each implements it its own way).

Worked example — model a parking lot. Extract nouns as classes: ParkingLot, ParkingSpot, Vehicle, Ticket. Extract verbs as methods: park, unpark, calculate fee. Relationships: a ParkingLot is composed of ParkingSpots — a spot has no meaning once its lot is gone, so this is composition (filled diamond on the lot). Car and Truck are Vehicles — that is inheritance. UML (Unified Modeling Language) is just the standard picture language to draw this: a class diagram for the structure above, and a sequence diagram to show Customer → Entrance → assignSpot() → issueTicket() in call order.

Key insight: good OOD comes from assigning each responsibility to exactly one class so things are highly cohesive (each class does one job well) and loosely coupled (classes depend on each other as little as possible).

✨ Added by the guide to build intuition — not from the source course.

🎯 Guided practice

  1. Easy — Model a Library book checkout. Goal: produce a class diagram and identify relationships.
    1. Extract nouns from the prompt: "A member borrows a book from the library and gets a loan record." Candidate classes: Member, Book, Library, Loan.
    2. Extract verbs as methods: borrow, returnLibrary.checkout(member, book), Library.returnBook(loan).
    3. Assign attributes by asking "what does each thing know about itself?" Book: title, isbn, isAvailable. Member: memberId, name. Loan: dueDate, links one Member to one Book.
    4. Decide relationships — and get composition vs aggregation right. A Library has-many Books, but a book exists independently of any one library, so this is aggregation (hollow diamond), not composition. Contrast with the parking lot, where spots die with the lot (composition, filled diamond): the test is lifecycle ownership. Loan associates exactly one Member with one Book — and it is its own class precisely because the relationship carries data (dueDate). Pattern learned: when a relationship itself carries data, promote it to a class (an association class).
  2. Medium — Model a vending machine and show its behavior. Goal: pick the right diagram for each question and apply polymorphism.
    1. Structure first (class diagram): VendingMachine, Product, Inventory, Payment. Make Payment an abstract base with CashPayment and CardPayment subclasses, each overriding process() — that is polymorphism: the machine calls payment.process() without knowing the concrete type. This keeps the machine loosely coupled to payment methods and open to adding new ones without editing existing code — the SOLID Open/Closed principle.
    2. Interaction over time (sequence diagram): Customer → VendingMachine.selectProduct()VendingMachine → Inventory.check()VendingMachine → Payment.process()VendingMachine → dispense(). Choose a sequence diagram because the order of messages between objects is the point.
    3. Two ways to model the dynamics — and they are different diagrams. If you frame the machine as the states it sits inIdle → ProductSelected → AwaitingPayment → Dispensing → Idle, with the transition "payment valid?" falling back to AwaitingPayment on failure — that is a state machine diagram (states + triggered transitions). If instead you frame it as the flow of actions a transaction performs, with a decision node and a loop on retry, that is an activity diagram. Use whichever the interviewer asks for, but do not call a state-named flow an "activity diagram" — that is the classic mislabel.
    4. Why this is the FAANG bar: you separated static structure (class diagram), interaction (sequence diagram), and dynamics (state machine or activity diagram), and used abstraction + polymorphism to make payment extensible. The reusable recipe: nouns → classes, verbs → methods, "varies by type" → abstract base + subclasses, "order of calls matters" → sequence, "branching workflow" → activity, "object moves through states" → state machine.

✨ Added by the guide — work these before the full problem set.

Lessons in this topic

🧠 Review & recall

Active recall is what moves a topic into long-term memory. Flip each card before revealing, then test yourself — your results are saved on this device.

Flashcard
What are the four principles (pillars) of object-oriented programming?
tap to reveal →
Encapsulation, Abstraction, Inheritance, and Polymorphism. Encapsulation binds data together and hides it (objects keep state private, accessed only via public functions); Abstraction hides all but the relevant data to reduce complexity; Inheritance creates new classes from existing ones; Polymorphism lets an object respond to the same message in different ways.
💡 "A PIE" — Abstraction, Polymorphism, Inheritance, Encapsulation.
Flashcard
How does OOP differ from procedure-oriented programming, and what is the difference between a class and an object?
tap to reveal →
Procedure-oriented programs are designed as blocks of statements that manipulate data, whereas OOP combines data and functionality and wraps it inside an Object. A class is the prototype/blueprint (a template of attributes and methods); an object is a concrete real-world entity built from that blueprint and is the basic building block of OOP.
💡 Class = recipe card; object = the actual latte handed to a customer.
Flashcard
What are the four steps of OO Analysis and Design, and what tool documents them?
tap to reveal →
1) Identify the objects in the system; 2) Define relationships between objects; 3) Establish the interface of each object; 4) Make a design convertible to executables via OO languages. UML is the standard tool used to document all this information.
💡 Identify → Relate → Interface → Design; UML is the camera that photographs it.
Flashcard
In a UML class diagram, what is the difference between aggregation and composition?
tap to reveal →
Both are forms of a 'whole-to-parts' association. In aggregation the PART's lifecycle is independent of the WHOLE (the child can exist without the parent — e.g., Aircraft without Airline). In composition the child's lifecycle depends on the parent's, so when the parent is destroyed the child is too (e.g., WeeklySchedule is destroyed when its Flight ends).
💡 Composition = 'dies with the parent' (filled diamond); aggregation = 'survives the parent' (hollow diamond).
Flashcard
What does multiplicity express in a class diagram, and how is a range like "0..*" or "2..4" read?
tap to reveal →
Multiplicity indicates how many instances of a class participate in a relationship — a constraint on the permitted cardinalities between two classes. "0..*" means 'zero to many' and "2..4" means 'two to four'. Example: a FlightInstance has exactly two Pilots, while a Pilot can have many FlightInstances.
💡 min..max on the association line; '*' = many.
Flashcard
When do you choose a sequence diagram versus an activity diagram, and how is each classified in UML?
tap to reveal →
Both are behavioral UML diagrams. Use a sequence diagram when the order of messages exchanged between objects over time is the point (tracks object interaction / dynamic modeling). Use an activity diagram when modeling the flow of control through a workflow or business process (functional modeling). A sequence diagram's vertical dimension shows message order chronologically and its horizontal dimension shows the object instances.
💡 Sequence = 'who calls whom, in what order'; Activity = 'the workflow/flowchart of actions'.
Q1. In OOP, encapsulation is best described as which of the following?
Q2. Per the lessons, which two UML diagrams are categorized as STRUCTURAL diagrams?
Q3. A WeeklySchedule object is automatically destroyed when its parent Flight object's lifecycle ends. Which class-diagram relationship does this represent?
Q4. Which statement correctly describes the Include vs Extend relationship in a use case diagram?
Q5. In a class diagram, the association between Pilot and FlightInstance is bi-directional, while Flight knows about Aircraft but Aircraft does not know about Flight. What is the Flight–Aircraft case called?