I want to model (TV)Events and Reminders and I’m wondering what’s ‘the best’ way to model this.
The requirements are roughly
- When an Event has no Reminder, a Reminder can be created
- When an Event has a Reminder
- the Reminder can be deleted
- an icon is shown on the Event
- A separate Screen exists presenting all Reminders
- Reminders are stored in the backend and have multiple properties
Obviously, our real domain is larger and also contains Channels, Recordings, ...
Basically, we need functions to
- create a Reminder
- delete a Reminder
- get the list of all Reminders
- check if an Event has a Reminder
This seems a relatively simple problem but I'm struggling with it. Below, I’ve collected a number of possible options and I would greatly appreciate your feedback.
Option 1
Event creates Reminders
Event API
Reminder createReminder() //adds the Reminder to the backend
boolean hasReminder()
Reminder API
void deleteReminder() //removes the Reminder from the backend
static List<Reminder> getAllReminders()
But
- deleting and creating a Reminder are symmetric functions and hence I would expect them on a single API (now both Event and Reminder have an interface to the backend)
- I'm not a big fan of the static function on Reminder. It seems to indicate that a higher-order object should exist
Option 2
Reminder API
Reminder createReminder(Event event) //adds the Reminder to the backend
void deleteReminder() //removes the Reminder from the backend
boolean hasReminder(Event event)
static List<Reminder> getAllReminders()
Advantage is that the Event API doesn't change when adding Reminder functionality (=> good wrt extendibility I guess). But
- creating a Reminder for a Event (and checking whether an event has a reminder) seems to be more a function on Event so I would expect them on the Event API
Option 3
Event API
Reminder createReminder() //adds the Reminder to the backend
void deleteReminder() //removes the Reminder from the backend
boolean hasReminder()
static List<Reminder> getAllReminders()
But
- the getAllReminders() seems more a function on Reminder
Option 4
Create a ReminderManager/ReminderService (singleton) with the following API
Reminder createReminder(Event) //adds the Reminder to the backend
void deleteReminder(Reminder) //removes the Reminder from the backend
boolean hasReminder(Event event)
List<Reminder> getAllReminders()
This is my preferred option but
- This results in anemic Event/Reminder objects (just getters and setters but no logic). There seems to be discussion whether this is an anti-pattern or not