Quantcast
Viewing latest article 10
Browse Latest Browse All 45

Inheritance versus composition: Which one should you choose?

One of the fundamental activities of an object-oriented design is establishing relationships between classes. Two fundamental ways to relate classes are inheritance and composition. Although the compiler and Java virtual machine (JVM) will do a lot of work for you when you use inheritance, you can also get at the functionality of inheritance when you use composition. This article will compare these two approaches to relating classes and will provide guidelines on their use.

First, some background on the meaning of inheritance and composition.

About inheritance In this article, I'll be talking about single inheritance through class extension, as in:

To read this article in full, please click here


Viewing latest article 10
Browse Latest Browse All 45

Trending Articles