Interfaces and Realizations

In previous lessons we learned how to refine classes from the interview with client, and relate them with different relationships between them. But it's possible that some of classes are not related to a particular parent, but their behaviors might include some of the same operations with the same signatures. You can code the operations for one of the classes and reuse them in the others.

note.GIF (411 bytes)An interface is a set of operations that specifies some aspect of a class behaviour, and it's a set of operations a class presents to other classes.
You model an interface the same way you model a class, with the rectangle icon, but interface has no attributes, only operations. Another way is with a small circle joined with line to a class.

The computer's keyboard is a reusable interface. Its keystroke operation has been reused from the typewriter. The placement of keys is the same as on a typewriter, but the main point is that the keystroke operation has been transfered from one system to another. Also on computer's keyboard you'll find a number of operations that you won't find on a typewriter (Ctrl, Alt, PageUp, PageDown...) 

interface-typewriter An interface is a collection of operations that a class carries out

To distinguish interfaces from classes, in stereotype construct we put <<interface>> or I at the begining of the name of any interface.

note.GIF (411 bytes)The relationship between a class and an interface is called realization. This relationship is modeled as a dashed line with a large open triangle adjoining and pointing to the interface.