Code Smells

The most important thing to remember about code smells is that they’re heuristics, not hard and fast rules. People have already pointed out that the Facade pattern looks a lot like a Middleman smell. So does the object adapter version of the Adapter pattern, or a convenience base class for decorator implementations. Parameter objects are most commonly data objects (though sometimes you may want to put functionality on them too)–this applies both to objects created to prevent long parameter lists/primitive obsesson/data clumps and those that only handle one primitive and just exist to help type safety (e.g., a wrapper class with a name explaining the intended function of its primitive value).

Basically, when code matches one of these definitions it’s a yellow flag–is the fact that it’s violating a code smell rule serving a legitimate purpose, or could the smell be fixed without other unpleasant consequences? If the latter, by all means fix it, but don’t expect to be able to go down a checklist like this and mechanically reject code.

2 Likes