CRC Cards (FIT2099)
Context: FIT2099_MOC Β· a lightweight, low-fidelity tool for evolving an OO design by working through scenarios Β· one index card per class Problem it solves: turn a domain scenario into candidate classes, their responsibilities, and who they collaborate with β spotting SRP violations early.
Quick Revision
- π― Trigger: need to sketch classes and how they interact before committing to code/UML β play βwhat-ifβ with ClassβResponsibilityβCollaboration cards.
- β‘ Key Constraint: if a card wonβt fit / canβt be rewritten succinctly, the object is doing too much β split it by SRP. Cards are great for thinking, poor for communicating to outsiders.
π The card format
- Three parts (Ward Cunningham, who also invented the wiki) β Class name (top) Β· Responsibilities (left: what it knows + what it does) Β· Collaborators (right: other classes it needs).
- Collaborators = associations β a collaborator listed on a card becomes an association/dependency in the eventual class diagram.
βββββββββββββββββββββββββββββββββββββββ
β Customer β
ββββββββββββββββββββββββ¬βββββββββββββββ€
β places orders β Order β
β knows name β β
β knows address β β
β knows customer number β β
β knows order history β β
ββββββββββββββββββββββββ΄ββββββββββββββββοΈ collaborations become a classDiagram
classDiagram class Customer { +placeOrder() +getOrderHistory() } class Order { +getTotal() +getOrderItems() } class OrderItem Customer --> Order Order --> OrderItem
(Each cardβs Collaborators column maps to an outgoing association β CRC is a fast way to discover the arrows before drawing the diagram.)
π Using the cards
- Start small β one or two obvious cards, then play βwhat-ifβ through a scenario; when the situation needs a new responsibility, add it to an object or create a new object; add collaborations as you go.
- Role-play β different people βplay the objectβ; messages become dialogue β βHey Unit, give me a list of students enrolled in youβ¦β; whoever holds that card acts it out; new responsibilities are added live.
- Direction is free β neither strictly top-down nor bottom-up β design βprogresses from knowns to unknownsβ (Beck & Cunningham); two teams reached the same design from opposite ends.
- Card too full β SRP β copy to a fresh card and state responsibilities more abstractly; if it still wonβt fit, the object does too much β split it by responsibility (SRP).
βοΈ Practice
Practice 1: A
Seminarcard's Responsibilities list grows to: name, number, fees, waiting list, enrolled students, instructor, add student, drop student, compute average mark, print transcript. What's the smell and the fix?Reference solution
- Smell: the card is overloaded β
Seminaris trying to do enrolment and assessment/reporting β SRP violation (a God Class in the making).- Fix: split responsibilities onto collaborators β an Enrollment card (marks, average, final grade) and a Transcript card (determine average mark) β leaving
Seminarwith roster/registration only.- Key move: βcanβt rewrite the card succinctlyβ is the CRC signal to Extract Class.
β οΈ Common Mistakes
- π‘ Not for outsiders β finished cards handed to a client as documentation were unintelligible out of context; CRC aids designersβ thinking (XP even de-emphasises diagrams), not stakeholder communication.
- π‘ No guarantee of good design β CRC encourages small objects with clear responsibilities (helps encapsulation and low connascence) but doesnβt guarantee quality β always keep the design principles in mind.
- π‘ Special notation optional β you donβt need the card notation; itβs a teaching/thinking aid, not a formal deliverable.