Realization specifies a contract between two or more types. Where one type (here Interface Imammals) defines the contract and the other type (Cat, Dog) promises to carry out.
Below code is a lazy example of Realization...
#include<iostream>
using namespace std;
class IMammals{
public:
virtual void walk() = 0;
};
class Cats: public IMammals {
public:
void walk() {
cout<< "Cat is walking" << endl;
}
};
class Dogs: public IMammals {
public:
void walk(){
cout<< "Dog is walking" << endl;
}
};
int main(void) {
Cats aCat;
Dogs aDog;
IMammals *ptrMammals = NULL;
ptrMammals = &aCat;
ptrMammals->walk();
ptrMammals = &aDog;
ptrMammals->walk();
return 0;
}
Using UML, realization is represented by an dotted arrow that points from the type two(Cat,Dog or Contractor) class to the type one class(IMammals or Contractee). The tip of the arrow is an empty triangle.
+-----------------+
| IMammals |
|-----------------|
| |
+---------|>| |<|--------+
| +-----------------+ |
| |
| |
+-----+-----+ +-----+-----+
| Cat | | Dog |
|-----------| |-----------|
| | | |
+-----------+ +-----------+