This question already has an answer here:
- Is type safety worth the trade-offs? 22 answers
So, we've got a guy who likes to write methods that take Objects as parameters, so they can be 'very flexible.' Then, internally, he either does direct casting, reflection or method overloading to handle the different types.
I feel like this is a bad practice, but I can't explain exactly why, except that it makes it more difficult to read. Are there other more concrete reasons why this would be a bad practice? What would those be?
So, some folks have asked for an example. He has an interface defined, something like:
public void construct(Object input, Object output);
And he plans to use these by putting several in a list, so it sort of builds bits and adds them to the output object, like so:
for (ConstructingThing thing : constructingThings) thing.construct(input, output); return output;
Then, in the thing that implements
construct, there is a rickety reflection thing that finds the right method that matches the input/output and calls it, passing input/output.
I keep telling him, it works, I understand it works, but so does putting everything into a single class. We're talking about reuse and maintainability, and I think he's actually constraining himself and has less reuse than he thinks. The maintainability, while probably high for him right now, will likely be very low for him and anyone else in the future.