Generally speaking, objects are been defined in terms of the classes. We know
lot about object by knowing about its class.
A D V E R T I S E M E N T
Even if you do not know what the
penny-farthing is, if I tell you it was bicycle, you would definately know that it
has two wheels, handle bars and the pedals.
The Object-oriented systems will take this step further and will allow the classes to
be defined in terms of the other classes. For an example, a mountain bikes, race bikes
and the tandems are all a different kind of the bicycles. In an object-oriented
terminology, the mountain bikes, the race bikes and the tandems are all subclasses of
a bicycle class. Similarly, bicycle class is a superclass of the mountain bikes,
race bikes and the tandems.
Inheritance Benefits
Subclasses provides the specialized behaviours from a basis of the common elements
provided by a superclass. Through use of the inheritance, programmers can reuse a code in
superclass many times.
Programmers can implement the superclasses that will define the "generic" behaviours
(called the abstract classes). Essence of superclass is defined and can be partially be
implemented but much of the class is been left undefined and also unimplemented. Other
programmers fill in details with the specialized subclasses.
Multiple inheritances
A subclass having more than one superclass is called Multiple inheritances.
This will enables a subclass to inherit the properties of more than one super class
and to combine all these properties.
Polymorphism
Different types of objects which respond distinctively to same message is called
Polymorphism, example, when we do send same message, �cost� to the spike-bicycle object,
a mono-cycle object and the tandem bicycle object, each of these object will respond
appropriately.
All these cycles of a class bicycle have their own individual price.
Data abstraction
Public interface, formed by a collections of messages understood by the object,
will define how to use this object. The programs which wants to manipulate the object,
will only have to be concerned about messages this object will understand, and need not
worry about how the tasks are achieved nor internal structure of an object.
Hiding up of the internal details makes the object abstract, and a technique is normally
known as the data abstraction.
Encapsulation
Packing up an object's variables within its methods is called encapsulation.
Encapsulating the related variables and methods into neat software bundle seems simple
but is a powerful idea that provides two benefits to the software developer:
Modular programming-- The source code for any of the object can be written and maintained
independently from those of the source code written for other objects. Also, an object can be
easily used passing around in the system. For example you can give your bicycle to someone else
and it will still work for them too.
Information hiding-- An object has a public interface by which other objects can
communicate with it. But on the other hand objects can maintain private information and methods
that cannot be communicated to others.