Inheritance:
When ever we any of us think about OOPS, Inheritance is one of the first concept that click in.
"The ability for a class to extend or override functionality of another class."
Inheritance is a way to reuse code of existing objects. Pre-existing class is called base class or super class and the new class is knows as derived class or subclass. The relationships of classes through inheritance gives birth to hierarchy.
Here Account is Base class and Checking A/c, Saving A/c, Credit A/c are derived classes from base.
In general terms, generalization and specialization both refers to inheritance but the approach in which they are implemented are different. If we have many object with similar behavior or properties and we craft a supper class by combining the common properties or behavior to cater the need of sub classes then it is called the Generalization.
In contrast to Generalization if new classes are created from existing class to perform or implement a specific feature this process is called Specialization. Both generalization and specialization are implemented using inheritance but the order of creation of the subclass and super-class drives the concept name.
Generalization:
Generalization is the process of extracting common characteristic from two or more classes and combining them into a generalized super class. Common characteristic can be attributes or behavior.
Example:
Consider the above figure, The Car and Scooter partially share common properties. During generalization all the common characteristic are combined and used to create a new class here say Vehicle. Car and Scooter become subclass of Vehicle.
In other word Generalization is all about bottom-up approach and identifying generic/common class. Specialization is just a reverse process ie. Top-Down approach.
Specialization:
Specialization is just the other side of generalization coin: Vehicle Generalize what is common between Car and Scooter, Car and Scooter specialize Vehicle to there own sub-type.
When ever we any of us think about OOPS, Inheritance is one of the first concept that click in.
"The ability for a class to extend or override functionality of another class."
Inheritance is a way to reuse code of existing objects. Pre-existing class is called base class or super class and the new class is knows as derived class or subclass. The relationships of classes through inheritance gives birth to hierarchy.
Inheritance |
Here Account is Base class and Checking A/c, Saving A/c, Credit A/c are derived classes from base.
In general terms, generalization and specialization both refers to inheritance but the approach in which they are implemented are different. If we have many object with similar behavior or properties and we craft a supper class by combining the common properties or behavior to cater the need of sub classes then it is called the Generalization.
In contrast to Generalization if new classes are created from existing class to perform or implement a specific feature this process is called Specialization. Both generalization and specialization are implemented using inheritance but the order of creation of the subclass and super-class drives the concept name.
Generalization:
Generalization is the process of extracting common characteristic from two or more classes and combining them into a generalized super class. Common characteristic can be attributes or behavior.
Example:
Consider the above figure, The Car and Scooter partially share common properties. During generalization all the common characteristic are combined and used to create a new class here say Vehicle. Car and Scooter become subclass of Vehicle.
In other word Generalization is all about bottom-up approach and identifying generic/common class. Specialization is just a reverse process ie. Top-Down approach.
Specialization:
Specialization is just the other side of generalization coin: Vehicle Generalize what is common between Car and Scooter, Car and Scooter specialize Vehicle to there own sub-type.
No comments:
Post a Comment