I'm having trouble designing an inheritance hierarchy.
In the figure:
Base class:
- This uses the Template Method.
- Contains core logic/algorithm that calls virtual/abstract methods
Derived types:
- These classes provides concrete implementation of the virtual/abstract methods expected by the Base.
Conditions:
- I have a virtual method (Run).
- The default Run method uses another virtual method (Proc).
- If a derived class uses the default Run behaviour, they must implement Proc.
- If a derived class overrides the Run behaviour, then it shouldn't have to care about the existence of Proc, let alone overriding it.
I've considered making Run() abstract and let each derived class handle their own. But then I'll end up with duplicate code.
I'm using a simplified example here.
In my actual project, I have several "Run"-typed virtual methods, each calling several "Proc"-typed methods.
Because of that, I have a whole bunch of virtual "Proc" methods with "throw new NotImplementedException()"
Creating a new derived type is also confusing, because the coder may not know which virtual methods must be implemented/can be ignored/etc.
I've considered using a strategy pattern, but since I have several "Run" methods, each one of those would have to be a strategy, which seems like overkill/overengineering.
Is there any way to simplify this?
[Update 1]
Here's an example that's closer to the kind of methods I'm working with
And imagine yet another method:
proc()
in the new diagram?getData()
?