A swiss army knife is a great tool to carry around with you. However, this anti-pattern tells us that building a one-stop-shop for your design functionality is a wrong approach. Several problems arise when you throw almost everything into a single class.
Defining the Swiss Army Knife Anti-PatternI found a good blog post on this anti-pattern to provide our definition. The article focuses on an interface, but it holds for a class in general as well. [Click Here to See The Page]
"Swiss Army Knife Interface is an interface class which has excessive number of method definitions. Architect/designer may design this interface to use for every need of the software, but this is a wrong approach and an antipattern. More than one interface must be designed using some design approaches."
We stumble onto the idea of what is a proper number of methods for an interface or class. Unfortunately, this is not a hard and fast rule. It is something that varies by situation. Thus, "too much" is left up to the designer and not a single number or even range, although 7-10 seems like a comfortable range for most people.
Design First, Then CodeIt may feel like we have gone down this path before. And we have. Many anti-patterns, including the swiss army knife, can be avoided with design and planning before you dive into implementation. However, in this case, there needs to be an on-going habit of designing before coding. When you skip that step, you can find yourself building a solution that grows ever closer to this anti-pattern.
Easy To MissThe toughest challenge with this situation is stepping back and seeing it approaching. It is far easier to tack on function after function without keeping the big picture in mind. When you stay in the weeds too much, it is easy to overlook the swiss army knife you have created.