Design/code reusage problem
Here is my issue.
I have a class. Lets call it GeneralClass. This class has a method, lets call it methodInQuestion(), which I need to change. Here's an example of how the code behaves now:
Code:
public void GeneralClass() {
methodInQuestion(ParentParameterType a) {
doGeneralThing();
}
I need to change it to something like this:
Code:
public void GeneralClass() {
methodInQuestion(ParentParameterType a) {
if(a instanceof ChildParameterType) {
doSpecificThing();
}
doGeneralThing();
}
The problem is however, that this is a poor design solution, since this specific behavior occurs very seldom, but my check would occur each time when this method is used. Instead of changing my general class, I created a new ChildParemeterType class and have overridden the method. That is a much better design solution, however, given that I have to copy-paste quite a large method for just one line of code, this solves my design problem only to create a reusage problem.
So my question is: how can I solve this problem in a way that I don't have to copy-paste and can reuse the code from my methodInQuestion() method.
Any advice or comments are appreciated.
Andrew