New answers tagged

1

Whenever I see a method where the behavior switches on the type of its parameter, I immediately consider first if that method actually belongs on the method parameter. For example, instead of having a method like: public void sort(List values) { if (values instanceof LinkedList) { // do efficient linked list sort } else { // ArrayList ...


4

If I try to make a new method to handle B differently, it gets called out for code duplication. Not all code duplication is created equal. Say you have a method that takes two parameters and adds them together called total(). Say you have another one called add(). Their implementations look completely identical. Should they be merged into one method? NO!!! ...


4

The usual saying that we all read here and there is: All problems can be solved by adding another layer of abstraction. Well, this is not true ! Your example shows it. I’d therefore propose the slightly modified statement (feel free to reuse ;-) ): Every problem can be solved by using THE RIGHT level of abstraction. There are two different problems ...


Top 50 recent answers are included