I have base two classes, Operation
and 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 Trigger
.
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?
Edit 1.
So the actual code looks like this. All the properties, are either a string
, Guid
, collection<string>
, or enum
. They are basically just represent small pieces of data.
Edit 2.
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.