Inheritance vs. Subtyping (webinar #24)

Поделиться
HTML-код
  • Опубликовано: 26 сен 2024
  • We discussed subtyping in OOP and implementation inheritance and compared how they are different and which one is good, which one is evil. The discussion was based on this article: www.yegor256.co...

Комментарии • 7

  • @gabrielslima
    @gabrielslima 2 года назад +2

    Great video!!
    Wanted to create a small summary about this. Pls correct me if i'm wrong:
    Inheritance (implementation inheritance): is a mechanism where one class inherits implementation from another class (since the attributes of this class - superclass - are public or protected). Implementation includes attributes (variables) and the behaviors (methods/functions) that are not abstract, they have a body, they have code.
    We have a "class to class" relationship. One class (subclass) has knowledge about the internals of another class (superclass).
    Implementation inheritance is all about code reuse. A subclass is a specification of a superclass and nothing guarantees that the contract (the promised behaviors by the superclass) will not be broken. A subclass can easily override the behaviors and do whatever it desires with it.
    Advantages:
    - Code reuse
    Disadvantages:
    - Breaks encapsulation because subclasses has knowledge about the internals of it's superclasses
    - Maybe a road to complexity. You have the possibility of having multiple ancestors to a class
    - Breaks Liskvo's Substitution principle
    - Promotes DIP violation
    - Promotes coupling between the classes (object's description/template)
    Subtyping (interface inheritance): is a mechanism where one class inherits the purpose/meaning of another type (supertype). Meaning the class actually inherits what was promised as behavior (functions/methods) to it's clients, and the implementation is kept at the class itself.
    Interface inheritance is all about preservation of purpose/meaning of a type. A subtype is the implementation (the actual code that will execute the behavior promised by it's supertype) of a supertype.
    You can have inheritance between the types(interfaces) since you have the scenario below:
    1 - One type only inherits the purpose of another type. Meaning no implementation, no variables are inherited. Only the overall meaning of the supertype
    2 - To implement a type that inherited another type's purpose, you'll have to implement all the promised behaviors of it's ancestors. So no contract will be broken
    Advantages:
    - Design by contract: clients of an object relies on the contract (the interface/supertype)'s description, and does not point's directly to the concrete versions of a class
    - Promotes Loosely coupled relationship between the objects
    - Promotes Liskov's Substitution Principle
    - Promotes Object Encapsulation
    - Reduces the complexity
    - Promotes proper reuse of code through use of objects
    Disadvantages:
    - At least from my perspective (maybe i'm wrong about this), you may end up with a proliferation of interfaces
    Thanks!!

  • @ArtemRomanov
    @ArtemRomanov 7 лет назад +8

    at 49:00 the connection is lost, what did you say about the new java 8 methods?

  • @adrianbuzea445
    @adrianbuzea445 7 лет назад +2

    I guess you can compare implementation inheritance with static methods. Because the parent classes, like your AbstractMetric example basically provide static methods, only with a scope restricted to the derived classes.

  • @alirezaRahmanikhalili
    @alirezaRahmanikhalili 6 лет назад

    inheritance is a type of polymorphism

  • @dementorpasha
    @dementorpasha 7 лет назад +1

    I want the same on Russian language! ;)

  • @katrykonig2466
    @katrykonig2466 3 года назад

    I don't know why some People dislike the Video?

    • @yegor256
      @yegor256  3 года назад

      Why do you think?