2

In object-oriented programming, when you extend a class you establish an is-a relationship between a new subtype and its parent(s), i.e. B is an A (aka code inheritance). When you compose a class with the help of existing types, you establish a has-a relationship between the newly composed type and the types it comprises, i.e. B has an A (aka object composition).

In many languages (e.g. Java), you have yet another way of defining types, namely by means of interface inheritance. How does one express this notion in natural everyday language?

For example, when a class B implements interface A in Java, do you also say that B is an A? Or do you express this concept differently? E.g. B implements Serizalizable, therfore B is serializable (or in other words: B has the attribute of being serializable).

In asking this question, I am not so much interested in the theoretic differences between these OO concepts (for which topic there are already sufficiently many questions) but rather the differences between them when expressing them in natural language (for which topic there don't seem to be any questions available yet).

gnat
  • 21,442
  • 29
  • 112
  • 288
zepp133
  • 221
  • 1
  • 5

2 Answers2

6

How does one express this notion in natural everyday language?

To make it short:

  • class inheritance describes a family of objects. In language terms, think of nouns.

Think of: vehicle, cars and bikes.

  • interface inheritance describes a set of unrelated objects, sharing common behaviour. In language terms think of adjectives.

Think of: able to fly, able to run etc.

Thomas Junk
  • 9,405
  • 2
  • 22
  • 45
3

Extending a class is not necessarily "code inheritance". If A is an abstract base class or an interface, then making B a subclass of it means it only inherits the interface of A. If A is concrete, then B would inherit the interface and maybe some code, depending on what B chooses to override.

So I believe the correct answer to your question is that inheriting from an interface, a concrete base class or an abstract base class would all result in an "is-a" relationship.

It may help to look up the Liskov Substitution Principle, as that is essentially the thorough, formal definition of what an "is-a relationship" is supposed to be.

Ixrec
  • 27,621
  • 15
  • 80
  • 87