Realization
Realization is also a type of inheritance but for interfaces. In a realization relationship, one entity (normally an interface) defines a set of functionalities as a contract and the other entity (normally a class) realizes the contract by implementing the functionality defined in the contract.
For example, a car is Drivable
(people can drive it), so it should have a drive()
function. Let's look at a coded example:
1// Drivable.js
2class Drivable {
3 drive() {
4 throw new Error("You have to implement the method drive!")
5 }
6}
7
8// Car.js
9class Car extends Drivable {
10 // Must implement all functions of Drivable
11 drive() {
12 // Do the driving here
13 }
14}
This code can be presented in UML by the following picture.
