HomeChallengesRepsProblemsLeaderboardTake a challenge

Pull the calendar out

Gregorian rules are baked into Date and MonthDay, so a second calendar would mean editing both. Make the calendar an object that is passed in, add the Julian calendar, and run the same model under each.

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

What you build

  • Create an abstract Calendar with abstract GetName and IsLeapYear, and virtual IsLeapDay and NextMonth
  • Add overloaded factories: Create(year, month, day) and Create(month, day)
  • Pass the Calendar into the Date and MonthDay constructors and delegate every rule to it
  • Add GregorianCalendar and JulianCalendar
  • Write Demonstrate(Calendar calendar, ...) and call it once per calendar

Done means

An abstract Calendar injected into Date and MonthDay, no calendar rules left in either, two factories, and both calendars demonstrated.

How it is graded

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

  1. Calendar is abstract, with an abstract IsLeapYear+20Let the object answer
  2. Date and MonthDay receive a Calendar+25Has-a beats is-a
  3. No calendar rules remain in Date or MonthDay+20Has-a beats is-a
  4. Two overloaded Create factories+10Let the object answer
  5. Efua’s celebration traced under both calendars+15Let the object answer
  6. Each calendar runs through the same Demonstrate+10Keeping the promises you inherit

What it teaches

Keeping the promises you inheritadvanced

Anywhere the parent works the child must work too — and a subclass that compiles perfectly can still break the first caller who relied on something the parent quietly promised.

The rest of Designing an Object Model