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

⚠️ 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.