This is the last part of the Modeling Class Relationship series of postings. In this posting the modeling of realization is discussed.
Realization
An interface is a kind of classifier that represents a declaration of a set of coherent public features and obligations. An interface specifies a contract; any instance of a classifier that realizes the interface must fulfill that contract - from UML Spec Page 82
An interface is a collection of method declarations without any mention of how they have to be implemented and any class that says to implement an interface should oblige in providing the implementation to the methods declared in the interface. Interfaces are merely declarations and are not instantiable. A class can implement multiple interfaces and an interface can be implemented by multiple classes. An interface is created when you want to separate the implementation of an abstraction from the desired behavior of the abstraction.
Realization is a specialized abstraction relationship between two sets of model elements, one representing a specification (the supplier) and the other represents an implementation of the latter (the client) - from the UML Spec Page 123
The supplier is the interface and the client is the class. Realization is graphically rendered as a dashed line (as in dependency) with a unfilled arrow head (like in generalization) pointing towards to the interface (the supplier) from the client (the client). An example of realization is shown below.
For example the relationship between Employee and ParttimeEmployee or FulltimeEmployee can be modeled as a realization relationship. See figure below.
Code Example:
public interface Employee {
public Long computeSalary();
}
public class ParttimeEmployee implements Employee {
public Long computeSalary(){
//implementation goes here
}
}