Polymorphic solution
In object-oriented programming, polymorphism provides a powerful way to abstract an interface of many forms. Polymorphism literally means many forms in Greek.
The common interface of the households contains a function called performService
to signal the start of the service, as well as a function called wasServicePerformed
to return true if the service was performed as per the agreement:
interface Service { fun performService(time: Instant) fun wasServicePerformed(): Boolean }
This solution can be illustrated in the following UML class diagram:
Figure 3.2 – Polymorphic solution
The Plumbing
class is relatively simple. It provides a function for the household to start the service, a function to report the service completed, and a function for the other household to confirm that the service has been performed. Meanwhile, timestamps are recorded that indicate when the service...