Class-based Inheritance and the “is-a” relationship
Traditional languages such as Java, Ruby, and C++ use a concept called class-based inheritance. To demonstrate this, I’ll use the classic example of an Animal and a Dog.
class Dog extends Animal
Using classical inheritance, Dog and Animal can be said to have an “is-a” relationship (ie: A Dog IS-A Animal). When a new instance of a Dog is created, the properties of Animal are also included in the properties of Dog.
Since a Dog “Is-A” animal, calling the method getSpecies() on the Dog class works. The method was automatically added to the “Dog” class by the inheritance system.
Prototypical Inheritance and the Has-A Relationship
In the example above, the “Dog” and “Animal” functions are completely separate from each other. The “Dog” object has a property called “prototype” which is set to an instance of a new Animal. Until the “prototype” property is set, there is no “inheritance” relationship.