| File | Change |
|---|---|
CourseState.java |
Fields name, configuration, clock, courseView, durationInMinutes changed from protected to private. Added transitionToOnGoing() and transitionToFinished(Instant) protected methods. Added Instant and ChronoUnit imports. |
YetToStartCourseState.java |
start() now delegates to transitionToOnGoing() instead of directly constructing OnGoingCourseState. |
OnGoingCourseState.java |
end() now delegates to transitionToFinished(startTime) instead of directly computing duration and constructing FinishedCourseState. Removed ChronoUnit import. |
Encapsulating CourseState's fields as private enforces the Law of Demeter within the hierarchy: subclasses interact with the parent through its interface (methods), not its data. This makes the base class's internals easier to change without ripple effects across subclasses.
- None. The refactoring is purely structural; no behaviour was altered.
FinishedCourseStaterequired no changes — it never accessed the fields directly.
- All five fields in
CourseStateare nowprivate. -
transitionToOnGoing()andtransitionToFinished(Instant)areprotected(accessible to subclasses, not public API). -
YetToStartCourseState.start()delegates totransitionToOnGoing(). -
OnGoingCourseState.end()delegates totransitionToFinished(startTime). - No subclass directly references a field from
CourseState. - All existing tests still pass (
mvn test).