I have an Event class that contains the start and end time of an event. Each Event object can have several related ChildEvent objects representing each repetition of the parent event. Each of these classes must take different actions depending on how they are edited, for example.
Removing only one event:
- Event: before the removal of the first parent, the parent of all other children
- ChildEvent: just delete as usual
Deleting an event and all subsequent events:
- Event: delete all child events and then delete itself
- ChildEvent: delete all future siblings, and then delete itself
Editing only one event:
- Event: make the first child the parent of all other children, then update
- ChildEvent: update yourself as usual
Editing an event and all subsequent events:
- Event: update all child events and then update itself
- ChildEvent: update all future siblings, then update yourself
Currently, I achieve this by checking conditions and taking appropriate actions, but it starts to get confused (there are other conditions with corresponding behaviors). I am curious to know how more experienced programmers can handle it (I use ruby). Any ideas?
Evan caine
source
share