@mrjayarajj Hi. Thanks for your comment. Inheritance does two jobs: 1. Helps with re-use through generalization (you only create/test the general parts once). 2. Lets you write frameworks against a base class or interface. (See my video on polymorphism). So in this video I'm demonstrating job 1 - re-use through generalization.
@mrjayarajj (continued) But you are correct, and this is a dilemma which OO designers often have to tackle. You can implement it with a delegate (HouseProperty) and it will work, but strictly speaking you are using a HAS-A relationship to model an IS-A relationship. Probably not a big problem in this simple case, but in a larger system with a few more layers of inheritance and a few more genuine HAS-A relationships (eg heating system) it could possibly be less clear to understand the design
By using inheritance we open the door to use polymorphism as well :).
Ie, We can have a super (base) class to have common properties and a getLocation() method (this is a use of inheritance), .
Then derived classes RentedFlat and RentedFlat classes and then these derived classes can re-define getLocation() (this is polymorphism, as getLocation() can be called regardless of the type)...
yo man, your tutorials are ill son! i'mma ace my principles of OOP paper tomorrow. catch you on the flipside, homie.
finecutmarmalade 11 months ago
well done video. Great real world example. Much better than the stupid triangle, square, shape one.
murph1329 1 year ago
great explanation really appreciate it.
eltonpiko 1 year ago
@eltonpiko Thank you for commenting - I'm glad you found this video useful
AgileJStructureViews 1 year ago
hai paul wells,
I have a doubt.
1. why we need inheritance here, why cant we archive using polymorphisms ?
eg: RentedFlat has HouseProperty and OwnerOccupiedHouse has HouseProperty
RentedFlat r = new RentedFlat();
r.getHouseProperty().getLocation();
OwnerOccupiedHouse o = new OwnerOccupiedHouse ();
o.getHouseProperty().getLocation();
mrjayarajj 1 year ago
@mrjayarajj Hi. Thanks for your comment. Inheritance does two jobs: 1. Helps with re-use through generalization (you only create/test the general parts once). 2. Lets you write frameworks against a base class or interface. (See my video on polymorphism). So in this video I'm demonstrating job 1 - re-use through generalization.
AgileJStructureViews 1 year ago
@mrjayarajj (continued) But you are correct, and this is a dilemma which OO designers often have to tackle. You can implement it with a delegate (HouseProperty) and it will work, but strictly speaking you are using a HAS-A relationship to model an IS-A relationship. Probably not a big problem in this simple case, but in a larger system with a few more layers of inheritance and a few more genuine HAS-A relationships (eg heating system) it could possibly be less clear to understand the design
AgileJStructureViews 1 year ago
@mrjayarajj
By using inheritance we open the door to use polymorphism as well :).
Ie, We can have a super (base) class to have common properties and a getLocation() method (this is a use of inheritance), .
Then derived classes RentedFlat and RentedFlat classes and then these derived classes can re-define getLocation() (this is polymorphism, as getLocation() can be called regardless of the type)...
wizman009 1 year ago