I have base two classes,
Trigger. Each has a number of subclasses which specialise in certain types of operations or triggers. A
Trigger can trigger a specific
Operation. Whilst an
Operation can be triggered by a specific
I need to write the code that maps a given
Operation to a given
Trigger (or vice versa), but I'm not sure where to put it.
In this case the code doesn't clearly belong to one class or the other class. So in terms of a single-responsibility principle I'm not sure where the code should belong.
I can see three options which would all work. Whilst 1 & 2 are appear to just be a choice of semantics, 3 represents a different approach entirely.
- On the trigger, e.g.
bool Triggers(Operation o).
- On the operation, e.g.
bool TriggeredBy(Trigger t).
- In an entirely new class which manages the mapping, e.g.
bool MappingExists(Trigger t, Operation o).
How should I decide where to place the shared mapping code in respect of a single responsibility principle?
How to manage single responsibility when the responsibility is shared?
So the actual code looks like this. All the properties, are either a
enum. They are basically just represent small pieces of data.
The reason for the return type of bool. Another class is going to consume a collection of
Trigger and a collection of
Operation. It needs to know where a mapping exists between a
Trigger, and an
Operation. It will use that information to create a report.