Designing with Objects: Deciding What Each Class Owns · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.
En anglais

Give every class one clear job

Computing · Programming · ages 16-18
Name ______________________   Date ____________
  1. Member owns contact details and must keep them valid. Which responsibility belongs with that data?

    • Change a book's repair status when its cover tears
    • Set loan dates from a library-wide lending policy
    • Check and update the member's contact details
  2. A cinema stores screenings, customer details and bookings linking a customer to a screening. Which set models these three record kinds?

    • Screening, Customer and Booking
    • Screening, Booking and SeatNumber
    • Customer, Booking and ScreenWidth
  3. Account has deposit and withdraw methods that maintain its balance. Having these two related actions does not by itself mean the class should split.

    Circle one:   True   False

  4. A Library class maintains catalog records and fee rules. A catalog team changes book details; a finance team changes fee policy independently. Which boundary follows those responsibilities?

    • Keep both together because they serve the same library
    • Separate catalog records from the changing fee policy
    • Move both jobs into one shared class-level dictionary
  5. Loan creates and updates the dates for one borrowing relationship. Book maintains bibliographic details. Where should that loan's due date be maintained?

    • Loan, which owns and updates that loan's dates
    • Book, which copies every loan's current due date
    • Both, with separately edited copies of the due date
  6. Catalog and FeePolicy have been separated. Catalog needs a fee calculation. How should the design preserve separate ownership while letting them cooperate?

    • Copy the fee rules into Catalog so both classes can edit them
    • Move all fields into FeePolicy so Catalog owns no records
    • Keep separate owners and use a defined request for the fee
  7. One class maintains member signup records and book-repair records. Their rules change independently. A split is chosen. Which change carries out that split?

    • Keep both jobs together and rename the class Coordinator
    • Separate signup state and methods from repair state and methods
    • Keep both jobs together and move their methods into __init__
  8. Member maintains and validates postal addresses. Checkout reads one to print a label. A designer wants Book to keep another editable address copy. Which boundary is justified?

    • Book owns the address because checkout prints the label
    • Member owns it; checkout requests it when needed
    • Member and Book each maintain their own address copy
LightMySky · lightmysky.comW1-mt_De_gpvpOzg-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Give every class one clear job W1-mt_De_gpvpOzg-s1

  1. Check and update the member's contact details · Checking and updating the contact details serves Member's stated maintenance responsibility.
  2. Screening, Customer and Booking · The requirements identify screenings, customers and their booking relationships. Seat numbers and screen width are not the three described record kinds.
  3. True · Both actions serve the same balance responsibility. Counting verbs or using and does not establish unrelated jobs.
  4. Separate catalog records from the changing fee policy · The two responsibilities have separate rules and independent reasons to change, which supports a boundary between them.
  5. Loan, which owns and updates that loan's dates · The due date describes the borrowing relationship whose dates Loan maintains.
  6. Keep separate owners and use a defined request for the fee · Catalog can request a calculation from FeePolicy without owning another editable copy of its rules.
  7. Separate signup state and methods from repair state and methods · A split moves each responsibility's state and maintaining methods together, then defines how the new owners cooperate.
  8. Member owns it; checkout requests it when needed · Member has the stated maintenance and validation duty. Checkout's read does not justify a second editable owner.
Worksheet · LightMySky