Hot answers tagged

2 votes

How to eliminate repetition in three subclasses: each defines an identical method that does almost the same thing, but with a different return type

As I see it, you have two possible solutions for this. Generics and the Visitor pattern. Personally, I would go with the second approach as I find it cleaner and more maintainable. In the first ...
Sebastian Sotto M.'s user avatar
1 vote

How to eliminate repetition in three subclasses: each defines an identical method that does almost the same thing, but with a different return type

I would implement it using generics similar to java.util.List<E> which has a method E get(int index) where <E> is the different returntype. Taking the minimal example code from Sebastan-s ...
k3b's user avatar
  • 7,518

Only top scored, non community-wiki answers of a minimum length are eligible