|
|
|
|
Why is Inheritance important?Have you ever written some code, and then later found that you needed to write something that was almost, but not quite, the same? What did you do?
Inheritance provides a mechanism to allow you to extend existing code in a natural way. Classifications, Taxonomies, and InheritanceHumans are always classifying things!
Classification enables us to deal with new things in terms of what is already familiar to us; reduces volume of information; helps simplify. We often call such classifications taxonomies. Taxonomies are everywhere -- for example:
Here are some more:
InheritanceInheritance is an abstraction mechanism which allows classes to be related hierarchically.
For example, consider the problem of drawing different kinds of graphical shapes. We can extract the common attributes and behaviors of any kind of shape, and encapsulate it in a Shape class:
The Circle, Triangle and Square classes inherit (or derive) their behaviors and properties from class Shape.
|
|
This page was last modified on 02 October, 2007 |