LightMySky

Designing with Objects: Deciding What Each Class Owns

Reading a problem description and deciding which things deserve a class, what each one is responsible for, and where the boundaries between them fall. The judgement is about responsibility, not about syntax.

No account needed. Progress saves in this browser.

What a learner can do afterwards

  • Pull candidate classes and responsibilities out of a written problem description
  • Defend a boundary: say why one piece of data belongs to this class and not that one
  • Spot a class that has taken on two unrelated jobs and split it

1 · Read

Object design starts on paper, not in code. Read the problem story and circle the nouns: those are your candidate classes. Then circle the verbs attached to each noun: those are its responsibilities, the jobs it must do. A library story gives Book, Member and Loan as first candidates.

Try it together

In the library story, borrow belongs to the loan process, not to the book alone, so Loan owns the borrow date and the link between one book and one member. Defend the boundary this way: the data lives with the class that uses it most, and methods sit beside the data they touch. If Book owned every loan date, its data would sprawl across jobs it never performs.

Keep each class to one job you can state in a single sentence. If you cannot finish the sentence without saying and, you likely have two classes wearing one costume. The symptom is a method split: half the methods touch one group of data and half touch another, while the class name no longer fits either half.

Good to know

Split early while names are still cheap to change. Move each data group plus its methods into its own class and connect them with a clean link. Let the constructor set every new object to a valid starting state, so no instance begins life half built.

Nouns suggest classes, verbs suggest duties, and any class needing and in its job splits in two.

2 · Watch

Take it off screen

Print a worksheetA4 with an answer key page for grown-ups. No screen, no internet.

Where it sits

Then practise

8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.

Spotted a problem on this page? Tell us
Designing with Objects: Deciding What Each Class Owns · Computing, ages 16 to 18 · LightMySky