In normal terms, they both refer to inheritance but the way in which it is implemented or looked into makes the difference. If many similar existing objects are combined to form a superclass to do the job of its subclass', then it is known as Generalization while if some new subclasses are created from an existing superclass to do specific job of the superclass, then it is known as specialization. Both concepts can be implemented using inheritance only. But the order of creation of the subclass and the superclass drives the concept name.
The way or perspective of looking also gives the difference between these two concepts. When you look from the perspective of a base class, it is generalization because the base class has functions or operations that may be commonly used by all of its subclasses. When you look from the perspective of the derived class, it is specialization because even though the common functionalities from the super class are available, the derived classes perform their own operations or functions specific to the purpose of their creation.
From the above figure, if you see from the perspective of the Train, then it is Generalization. The common functions or operations of both the Passenger and Goods Trains are put into the Train such as startTrain, stopTrain, fillFuel. That is, the generic operations of any subclass of Train are included in Train.
If you see from the perspective of the subclasses (Passenger Train or Goods Train), then it is Specialization. The common functions of the superclass (Train) are also included with the specific functions of the subclass such as boardPassengers, cleanToilet, fillWater, fillPantryResources in case of Passenger train and loadGoods, unloadGoods in case of Goods train making the subclass, a class for a specific or special function.
Note: In case of Generalization, it is not necessary that the superclass (Train) should know about the existence of its subclasses (Passenger Train and Goods Train). In case of Specialization, the subclass will always know its superclass.
22 comments:
nice explaination...with a simple example ... keep it up
nice explanation.........amit sharma.
very well explained nice!!!
good example...
really gud explaination
wonderful example
it was good
very nice explanation good job
nice explanation.........ramkrishna
very nice explaination.......
But i need implementation of these two in C#.net....if possible plg give ....... vijaylaxmi
I was easy t understand the concept through this thanks.....
good explaination............
karamdeep kaur
good explanation.can u provide more details
nice explaination...with a simple example ... keep it u
nice explaination...with a simple example ... keep it u
Good one yaar...........
Good one yaar...........
Very good explaintion with examples.
Nice explaintion with example.
Simple yet effective. Thanks :)
Ahsan Mustafa Bhatti
very nice and useful. Great explanation.
it is really a very good and helpful explanation of the concept with a really simple example ! thanks a lot,,
Post a Comment