КОМЕНТАРІ •

  • @pablon3115
    @pablon3115 2 роки тому +2

    Thanks for such a good explanation and example. What I understood is:
    Delegation allows having multiple implementations of an interface so then, the base class implementing that interface has to override the interface method. At this point it will be possible to make use of any of the implementations of the interface in the body of the overriden method of the base class and in Kotlin we can perform it from the class definition. Example:
    class ClassI : InterfaceX by ClassAThatImplementInterfaceX()
    class ClassJ : InterfaceX by ClassBThatImplementInterfaceX()
    I wish it can help others to understand it easier (although the example in the video is perfectly clear) and not to bog down the path xD

    • @CodyEngelCodes
      @CodyEngelCodes 2 роки тому

      Yup that's a great explanation and happy to hear this video helped you!

  • @Bellatronix
    @Bellatronix Рік тому

    Thanks for you explanation!
    It seams that the main purpose of class delegation in Kotlin was to overcome restriction of multiple inheritance in classes. Just like traits in PHP you can assemble target Kotlin class from pieces (i.e. various classes-delegates) using multiple inheritance of interfaces with "by" syntactyc shugar. So, instead of the following that won't compile
    class Cat: FastMover(), Carnivoure() { ... }
    we can make it working with class delegation feature
    class Cat: CanMove by FastMover(), CanEat by Carnivoure() { ... }

  • @syprosegwako8297
    @syprosegwako8297 Рік тому

    Great explanation!!

  • @jawadyousaf2475
    @jawadyousaf2475 4 роки тому +2

    Simple and to the point explanation

    • @CodyEngelCodes
      @CodyEngelCodes 4 роки тому

      Thanks Jawad, happy to hear this was helpful!

  • @MuzefferPasazade
    @MuzefferPasazade 4 роки тому +3

    Super! Thank you very much

  • @nandityanuswatama4394
    @nandityanuswatama4394 4 роки тому +1

    your video is help me so much, thanks!

    • @CodyEngelCodes
      @CodyEngelCodes 4 роки тому

      You’re welcome! Happy to hear it helped 🙂

  • @anubhavsharma1335
    @anubhavsharma1335 3 роки тому

    Thanks it really helped me understand.

    • @CodyEngelCodes
      @CodyEngelCodes 3 роки тому +1

      Yeah you’re welcome, happy to hear it helped ☺️

  • @misterjedu
    @misterjedu 4 роки тому

    Thanks for the explanation. It makes more sense to me now why delegation/composition it's better than inheriting or using abstract classes
    However, from the example you gave, the delegation it's still a bit rigid. The cat should not enjoy the steak. It should have returned false.
    I've seen an example where that is taken care of in the constructor (In this case, the Cat constructor) to make it much more flexible, but I was confused with the explanation.
    I was hoping to get a better explanation here.

  • @dnkilic
    @dnkilic 4 роки тому +1

    Great Job! I would like to listen SOLID from you as well!

    • @CodyEngelCodes
      @CodyEngelCodes 4 роки тому +2

      Thanks! SOLID is a good one that I’d love to do a video series on.

  • @GameOnStreamTV
    @GameOnStreamTV 4 роки тому

    it was really helpful for me! thanks!

  • @bolafahmi
    @bolafahmi 4 роки тому +5

    Finally an explanation that makes sense! Thanks a lot man..

    • @CodyEngelCodes
      @CodyEngelCodes 4 роки тому +1

      Thanks Bola, I’m happy this explanation worked for you 😌

  • @wintersijan
    @wintersijan 4 роки тому

    Thanks a lot!!🤗

  • @vikaspandey7053
    @vikaspandey7053 5 років тому +1

    good explanation

  • @soma7891
    @soma7891 2 роки тому

    Can somebody explain me with a more practical example what delegation is?

  • @donwald3436
    @donwald3436 2 роки тому

    So it's multiple inheritance?

    • @CodyEngelCodes
      @CodyEngelCodes 2 роки тому

      Yeah, basically multiple inheritance through composition with interfaces.

  • @OlivierGeorg
    @OlivierGeorg 3 роки тому

    So what is the difference between class Cat: CanMove by FastMover() {...} and class Cat: FastMover {...}

    • @CodyEngelCodes
      @CodyEngelCodes 3 роки тому

      The `by` keyword will use the classes interface definition for those interface definitions on the class. So your first example, Cat would use the FastMover implementation of CanMove while allowing you to implement other interfaces (using their own `by` keyword). Your second example would require FastMover to be `open` so it can be inherited from `Cat`, Kotlin only allows for inheriting from one parent class.

    • @notkamui9749
      @notkamui9749 2 роки тому

      you don't wanna expose that your Cat is specifically a FastMover (as in, FastMover shouldn't be an exposed type)

  • @MirrorsEdgeGamer01
    @MirrorsEdgeGamer01 4 роки тому

    Good video. However, you spelt Carnivore wrong. IntelliJ was saying you spelt it wrong.

    • @CodyEngelCodes
      @CodyEngelCodes 4 роки тому

      I never was very good at spelling 😅

  • @wisnu7734
    @wisnu7734 4 роки тому

    Honestly...C# is more simple to implement delegate....