So assuming in class C, the method had no parameters, I would have in Parent: public abstract getValue();
So that code below works fine.
But since class C, requires a parameter, it complicates things.
I'm not sure of the correct way of handling this, I can think of a few ways, but they seem a little cumbersome, and I would really like keep the method name "getValue" the same, since it really does the same job in A, B and C.
Can anyone show me the 'official' way to handle this, if there is such a way.
You want to use the reference type as the "parent" and expects to send similar messages to all object it refers; no matter what the implementation class is.
Your issue is in choosing overriding vs overloading.
In overloading you have to use reference types of those classes where the method definitions are.
But in overriding you can use the reference type of the parent class.
So your question is how to convert overloading to overriding. The solution Fred explained above is one.
Another solution is to keep the parameter as a class variable and make sure it is set during construction. But what if this variable don't have anything to do with the state of the object C.
The actual issue is with type differentiation. Below is a similar example.
Here petalId is not representing the state of Flower. So it shouldn't be part of the state of Flower. But it is Ok to have Flower to have a method getPetal(int petalId) eventhough petalId is not used.
So if the parameter don't represent state, Fred's solution is better.
If the parameter represent state, my solution is better.