Here is a piece of cool code to add the two integers, a and b:

NameService nameService = NameService.getSingletonInstance();
OperationService operationService = nameService.resolve(OperationService.class);
ValueFactory factory = OperationServiceFactory.newInstance();
AbstractValue va = factory.newIntegerValue(a);
AbstractValue vb = factory.newIntegerValue(b);
Operator operator = operationService.resolve(AdditonService.class);
AbstractValue vc = operator.performOperation(a, b);
int c = nameService.resolve(IntegerDecorator.class).getValue(vc);

Unfortunately I cannot paste the actual production code that does a little bit more (while not much) but the problem should be obvious: there is much more code than minimally required and despite of "design patterns applied" it is very difficult to read or refactor it. It can be written much simpler and shorter but the author of the code claims you being unprofessional for saying so. Where is the problem with the code? It really could not be that there is no any.


1 Answer 1


You could call this Cargo cult programming where the programmer uses patterns without fully understanding why. Before you go accusing someone of this, make sure you understand the reasons behind these patterns yourself.

This isn't the actual production code, you said so yourself. Therefore you have to seriously consider the possibility that this might be even necessary under the circumstances. Even the code you wrote might actually be feasible in the right circumstances, such as in a code parser where operators and operands are all potentially dynamic.

Perhaps the author of this code merely meant to be as flexible as possible. It is questionable whether or not the added flexibility is worth the lack of readability.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.