Friday, October 29, 2010

HYBRID INHERITANCE



A program (frequently called "class") can be used to create a new program that will include the original characteristics of the original program, and it allows the replacement of some of those characteristics, and the addition of new ones.

One of the key characteristic of inheritance is the fact that changes ocurred in the original program (class) will automatically be incorporated in the programs using that class.

Inheritance is the meachanism by which a class can use the properties of another class. In c++ parlance, the class which inherits the properties of another class is called derived class and the class from which the properties are inherited is called base class.

Inheritance is the essence of OOP 'cos it provides reusable code. so the programmers effort is much abated beacause the code is already tested and debugged.

You can achieve Inheritance in many ways. The patterns in which you can classify this methodology are:

  1. Single Inheritance - no quite
  2. Multiple Inheritance
  3. Multi-Level Inheritance
  4. Hybrid Inheritance and
  5. Hierarchial Inheritance.

The above mentioned patterns of inheritance are very simple..as simple as kicking a football.

Single inheritance is the one where you have a single base class and a single derived class.

Ex: class base{
private:
..........
.....
public:
....
.....
};

class derived:"Mode" base
{
.......
.......
public:
}

"mode" can be private , public or protected. In public mode all the public data members and member functions of the base class become the public ones for the derived class and other data like protected and private of the base class is not inherited.

In private mode, public and protected data/ functions of the base class become the private data/functions of the derived class.Private data is never inherited.

In protected Inheritance, public and protected members of base class become protected members of the derived class and as said b4, private data is not inherited.

In Multiple inheritance, a derived class inherits from multiple base classes. It has properties of both the base classes. Suppose i wanna make a plant class.

for it's survival it needs sunlight for photosynthesis and water. so sunlight and water are 2 classes from which the plant class is derived.

class sunlight{...};
class water{......};
class plant : "mode" water,sunlight{........};

In Multi level inheritance, a class inherits it's properties from another derived class.

A--->b----->c

  • A is the grand parent
  • B is the child of A & parent of C.
  • so the class c inherits all the properties of A and B (as well as it's own data and member functions).

In hierarchial Inheritance, it's like an inverted tree. So multiple classes inherit from a single base class. It's quite analogous to the File system in a unix based system.

Finally, a hybrid inheritance pattern is a combination of any 2 of the above discussed patterns...
----------------------------------------------------------------------------------------------

A C++ PROGRAM TO IMPLEMENT HYBRID INHERITANCE

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :3 kb

EXE FILE SIZE :580 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C++ PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.


----------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

0 comments:

Post a Comment