View RSS Feed

Java Basic

Inheritance vs. Composition

Rate this Entry
by , 01-08-2012 at 11:55 AM (2677 Views)
The concept of inheritance is based on is a relationship. Composition is based on has a relationship. Both of these two concepts allow placing sub objects into your class. Below image explains this key relationship.

Name:  48.JPG
Views: 1341
Size:  25.3 KB

Inheritance Vs Composition

Inheritance is based on one direction concept. You can not apply it in reverse. Extends keyword is used to specify inheritance.

Composition is used in cases in which there is a stronger relationship between entities. For example house has a bathroom. It will be replaced with composition when mapping it into object oriented.

Submit "Inheritance vs. Composition" to Facebook Submit "Inheritance vs. Composition" to Digg Submit "Inheritance vs. Composition" to Submit "Inheritance vs. Composition" to StumbleUpon Submit "Inheritance vs. Composition" to Google