A date-handling module is being designed. Sort each item by whether it should be public or private.
Groups: Public interface · Private internals
- The scratch buffer the formatter reuses between calls
- A function that adds a number of days to a date
- A function that reports whether a year is a leap year
- A function that formats a date as a string
- The lookup array of month lengths used internally
- A helper that converts a date into a day count since 1970
Hints
- Ask of each item: does another module need it to do its own job, or is it only machinery?
- Anything a caller could break by touching, or that could be rewritten tomorrow, should be private.
Show the answer
Public interface: A function that formats a date as a string, A function that reports whether a year is a leap year, A function that adds a number of days to a date
Private internals: The lookup array of month lengths used internally, A helper that converts a date into a day count since 1970, The scratch buffer the formatter reuses between calls
The public interface should be small and stated in terms of dates, not of the machinery that manipulates them: format, leap-year test and date arithmetic. Month-length tables, internal day counts and scratch buffers exist only to make those work, and publishing them would let callers couple to details you wanted to be free to change.
Practise Modular Decomposition and Reuse
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Modular Decomposition and Reuse
- Two modules each work perfectly and fail when combined. What kind of defect does that suggest, and why do…
- Match each modular-design term to what it describes.
- SavingsAccount extends Account and overrides applyMonthly(). A variable declared as Account is holding a…
- The same block of validation logic has been copy-pasted into six files. Select every consequence the lesson…
- Order the steps of factoring duplicated logic into one reusable unit.