January 31, 2010

interface code smells

Interfaces are a very useful language feature, but are much abused. Symptoms include:
  1. An interface is only implemented by one class
  2. A class implements multiple interfaces. Often touted as an advantage of interfaces, usually it means that the class in question is violating the principle of separation of concerns.
  3. There is an inheritance hierarchy of interfaces (often mirrored by a hierarchy of classes). This is the situation you're trying to avoid by using interfaces in the first place. Too much inheritance is a bad thing, both for classes and interfaces.
All these things are code smells, IMO.
(Jim Cooper)
Why do most system architects insist on first coding to an interface? - Stack Overflow
Blogged with the Flock Browser

1 comment:

Indrit Selimi said...

I think that the "code smells" are too generic too be "true" smells. It depends much by the context, therefore the "smells" aren't always applicable.
It seems to me "too simple" to define these rules therefore I don't agree.