Inheritance in object oriented programming means that a class of objects can inherit properties from another class of objects. Imagine how much work this saves. With inheritance, you don't have to start from scratch! in object oriented programming means that a class of objects can inherit properties from another class of objects. Imagine how much work this saves. With inheritance, you don't have to start from scratch! When inheritance occurs, one class is then referred to as the parent class or superclass or base class. In turn, these serve as a pattern for a derived class or subclass. Inheritance is an important concept since it allows reuse of class definition without requiring major code changes. Inheritance can mean just reusing code, or can mean that you have used a whole class of object with all its variables and functions. Why not reuse an existing class that has behaviours similar to what you need in a new program? There are many forms of inheritance depending on what properties can be inherited (eg: instance variables, methods, values) and on how and when inheritance takes place (e.g. Does inheritance occur statically or dynamically? Can inherited properties be overridden or suppressed? How are conflicts resolved? etc.) Now isn't that typical? It always seems to get more complicated. Actually, it's not that bad. Some simple explanations of inheritance possibilities are listed below. |
| Class Hierarchy A subclass that has been 'derived' can also become a 'superclass' class for a new subclass. Multiple levels of classes that are derived from each other are said to form a class hierarchy. Each class in the hierarchy inherits the member variables and member functions of its respective superclass. By making use of these hierarchies, you can not only write code that is reusable, you can write whole data structures (classes) that are re-useable. |
Partial, Single and Multiple Inheritance There are various kinds of class-based inheritance. With single inheritance, a subclass may inherit instance variables and methods of a single parent class, possibly adding some methods and instance variables of its own. A natural extension to simple inheritance is multiple inheritance. Multiple inheritance occurs when a subclass can inherit from more than one parent class. Another interesting variation on class-based inheritance is what we call partial inheritance. In this case we inherit some properties and suppress others. Partial inheritance is therefore convenient for code sharing, but it can create a mess of a class hierarchy. |
|
Inheritance is an incremental modification mechanism. In other words, a code reuse mechanism to incrementally build new objects out of old ones. Incremental modification means that an object can inherit something...and later, inherit more. |
Class-based inheritance is an important mechanism which can simplify large pieces of software by exploiting the similarities between certain object classes. The key idea of class-based inheritance is to provide a simple and powerful incremental modification mechanism for defining new classes that inherit properties from existing classes. A class does not have to be modified if it is close to what is required: a derived class can be created to specialise it. Oh Oh...complicated again. Not really. Creating a subclass to alter a method or to add a method to a parent class is an example. Class-based inheritance is essentially a static form of inheritance: new classes inherit properties when they are defined (at compile-time) rather than at run-time. Once a class has been defined, the properties of its instances are determined for all time). |
Dynamic inheritance allows objects to change and evolve in the course of interactions between objects. More specifically, dynamic inheritance refers to the ability to add, delete or change acquaintances of objects at run-time. This can occur because an object changes its behaviour by accepting new parts from other objects, or because an object reacts to changes in the environment so that when changes in the environment occur, the behaviour of the object changes.
|
VISIT AN AREA IN OzEdweb