Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

This question already has an answer here:

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).

share|improve this question

marked as duplicate by Jarrod Roberson, amon, gnat, Snowman, durron597 May 25 at 0:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.