HomeChallengesRepsProblemsLeaderboardTake a challenge

Tell, don’t ask

SchoolSystem asks the child for its birth year, month and day, then does every piece of date arithmetic itself. Move each piece of work to the object that owns the data, until GetBeginning asks for nothing.

Intermediate15 min on the clock5 graded checks · 100 pointsDesigning an Object ModelPro
Graded by reading your code against the checklist below.

What you build

  • Give Child a Date birthdate and remove the three getters
  • Add Child.GetDateByAge(int age)
  • Add Date.GetFirstOccurrence(MonthDay day), with MonthDay helping
  • Rewrite GetBeginning as one chain of calls
  • Trace both start dates into Answers.cs

Done means

No getters for the birth parts, a one-line chain in SchoolSystem, date arithmetic only in Date and MonthDay, and both dates traced.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else.

  1. Child hands out none of its data+25Tell, don’t ask
  2. GetBeginning is one chain of calls+20Tell, don’t ask
  3. SchoolSystem does no date arithmetic+20Tell, don’t ask
  4. Both start dates traced correctly+25Tell, don’t ask
  5. The new methods are named in domain terms+10Tell, don’t ask

What it teaches

The rest of Designing an Object Model