Behavior in object-oriented systems is a reflection of the interaction of objects. If you change the objects, or alter their interaction, the resulting behavior changes.
This means that objects have relationships to other objects, usually through references that are used to call methods. The Gang of Four recommends that these relationships should be defined based on how the objects look to each other, not by how the objects are implemented.
It’s easy to misinterpret this to mean, “every object should have a separate interface,” referring to the type “interface” that many languages provide. But the advice was not meant to indicate any language-specific idiom.
An “interface” means any defined means of communication. A method signature is an interface. The collective public methods of a class are an interface. An abstract class is an interface. And so forth.
What is meant is that the interface of any interaction should be based on what is needed by the clients and not the way the behavior is implemented. Changing the implementation should not affect the interface, and thus should not affect the clients.
In other words, the full version of this is “design to interfaces (how an object behaves) rather than implementations.”
This is Scott Bain. Visit us at www.netobjectives.com.