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-Pattern

I 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.

SUNJACK

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 Code

It 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 Miss

The 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.

SmartHome 5% Off Coupon SPR5OFF good until 6.30.17 Home Security and Home Automation!

Rob Broadhead

Rob is a founder of, and frequent contributor to, Develpreneur. This includes the Building Better Developers podcast. He is also a longtime student of technology as a developer, designer, and manager of software solutions. Rob is a founder and principle of RB Consulting and has managed to author a book about his family experiences. In his free time, he stays busy raising five children (although a few have grown into adults). When he has a chance to breathe, he is on the ice playing hockey to relax.

Leave a Reply