HomeChallengesRepsProblemsLeaderboardTake a challenge
TRACK 08

Object-Oriented C#

One school calendar, from a date stored as a number to a model a thirteen-month calendar plugs into. Objects, polymorphism and design, one fix at a time.

18 challenges8 free4h of build time
Before you start

Assumes you can read basic C#: variables, methods, if and loops. Nothing about classes is assumed — the first sprint starts before objects exist, and it is free in full.

Designing an Object Model

Classes that do one thing, ask nobody for their data, and take new features without being edited.

  1. Print something usefulConsole.WriteLine(efua) prints "Child". Make it print the child — with each class formatting only its own part.Beginner · 5 min
  2. Tell, don’t askSchoolSystem 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.Intermediate · 15 min · Pro
  3. Pipelines and selectorsDate and MonthDay give the right answers and are procedural inside: a while loop, ifs with early returns, a temporary variable. Rewrite them so that no method has a body block.Intermediate · 10 min · Pro
  4. Write the top line first“As a parent, I want to know when my child first celebrates a birthday at school.” Write the answer as one line that calls methods which do not exist yet, then make them exist.Intermediate · 15 min · Pro
  5. Pull the calendar outGregorian 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.Advanced · 20 min · Pro
  6. Delete the switchThree methods switch on the same channel code. Product wants Mobile Money next, which today means editing all three. Replace the code with a class per channel, then add Mobile Money as one new class.Advanced · 20 min · Pro
  7. Cheapest channelGiven the registered payment channels, return the cheapest one that can take the amount: the first one on a tie, and null when none can.Intermediate · 15 min · Pro
  8. Capstone: add the Ethiopian calendarAdd a thirteen-month calendar to the model without editing a single existing class. The Ethiopian calendar has twelve months of 30 days, then Pagume with 5 days — 6 in a leap year, which comes when year % 4 == 3.Advanced · 25 min · Pro