Added: 2 years ago
From: AgileJStructureViews
Views: 4,632
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (8)

Sign In or Sign Up now to post a comment!
  • yo man, your tutorials are ill son! i'mma ace my principles of OOP paper tomorrow. catch you on the flipside, homie.

  • well done video. Great real world example. Much better than the stupid triangle, square, shape one.

  • great explanation really appreciate it.

  • @eltonpiko Thank you for commenting - I'm glad you found this video useful

  • 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().getLocati­on();

    OwnerOccupiedHouse o = new OwnerOccupiedHouse ();

    o.getHouseProperty().getLocati­on();

  • @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

  • @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 getLocati­on() method (this is a use of inheritance), .

    Then derived classes RentedFlat and RentedFlat classes and then these derived classes can re-define getLocati­on() (this is polymorphism, as getLocati­on() can be called regardless of the type)...

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more