Skip to content
Ameen Abozaid
BEG-028

OOP design practice

  • 5 Lessons
  • 59 min of reading
  • 6 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Modeling real-world domains
  • identifying responsibilities
  • avoiding god classes

Learn first

59 min of reading · 6 h of practice (estimate)

Learning outcomes

  1. Model a new domain (e.g., a parking garage) from a written description into classes, interfaces, and relationships.
  2. Assign each responsibility to the class that has the information to fulfil it.
  3. Spot and split a "god class".
  4. Explain their design trade-offs to a reviewer.

Lessons

  1. 01From requirements to classes: worked example12 min read
  2. 02Assigning responsibilities12 min read
  3. 03Recognizing and splitting god classes12 min read
  4. 04Explaining a design11 min read
  5. 05Demo: modeling the parking garage from requirements12 min read

Lab and exercises

Lab

BEG-028-LAB1 · Parking garage

Outcomes: 1, 2, 3, 4 · Time: ~6 h Model and implement a garage with levels, spot sizes, vehicles, tickets, and fees. Produce a UML diagram, working code, and a half-page design rationale covering key decisions and trade-offs. Complete a peer review of another learner's design (and receive one). Acceptance: UML + code + a half-page design rationale; peer review completed.

Exercises (assessment: design review using the rubric in the course assessment framework, design dimension)

IDOutcomeTask
BEG-028-EX011From the text "A cinema has screens; each screen shows movies at times; customers buy tickets for a showing", list classes, relationships, and one invariant.
BEG-028-EX022Decide which class should own: isSoldOut(), price(), canFit(vehicle). Justify each.
BEG-028-EX033Given a ShopManager with 12 methods (pricing, stock, email, file saving), propose a split.
BEG-028-EX044Write a five-line rationale for your cinema design including one rejected alternative.
BEG-028-EX051, 2Spot the premature inheritance: a Vehicle hierarchy with Car, Truck, ElectricTruck, OldTruck where the subclasses differ only by one number. Propose a simpler model.
Show solutions
  • EX01 Classes: Cinema, Screen, Movie, Showing, Customer, Ticket. Cinema 1—* Screen, Screen 1—* Showing, Showing *—1 Movie, Ticket *—1 Showing. Invariant: a showing cannot sell more tickets than its seats.
  • EX02 Showing.isSoldOut() (knows seats sold); Showing/a PricePolicy for price(); Spot.canFit(vehicle) (knows its size). Rule: the class with the data does the work.
  • EX03 For example PriceCalculator, StockLevel/Inventory, EmailNotifier, ShopRepository, leaving Shop as a thin coordinator.
  • EX04 Should name classes, a main decision (e.g., fee as a separate policy for easy change), and a rejected option with its trade-off.
  • EX05 One Vehicle class with a size/VehicleType field (or a small enum). Inheritance is not needed when only data differs.
  • The lab is graded with the design dimension of the rubric in the course assessment framework.

Quiz

Outcomes: O1 modeling · O2 responsibilities · O3 god classes · O4 explaining a design.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1A good first step in modeling from a description is to:O1
  2. 2Nouns in a description become:O1
  3. 3Premature inheritance means:O1
  4. 4Where should Ticket.isExpired(now) live?O2
  5. 5The best home for a behavior is the class that:O2
  6. 6A sign of a god class is:O3
  7. 7An anemic class:O3
  8. 8To split a god class you:O3
  9. 9In a design explanation you should:O4
  10. 10A reviewer finds a flaw in your design. A good response:O4

Practical part

Design review of the parking garage with the design dimension of the course assessment framework, the exercises BEG-028-EX01 to EX05, and a completed peer review. Pass: the design rubric's passing level plus the quiz at 7/10.

Common mistakes

Anemic classes with all logic in one manager; premature inheritance.

Assessment

Design review using the rubric in assessment/framework.md (design dimension).

Career relevance

Design reviews (MID-066) and DDD (MID-060).

Type to search levels, phases, modules and lessons.