Golang: Composition Over Inheritance

Поділитися
Вставка
  • Опубліковано 15 лип 2024
  • How does Go handles composition over inheritance? What does it mean to be a truly object oriented programming language when there isn't inheritance at all?
    Go is touted to be an object-oriented programming language. But...
    underneath it all is something else. Many people have wondered why Go team don't use inheritance? Normally in OOP, inheritance is used. However, Go doesn't use inheritance. Instead it prefers composition over inheritance. And the big question is why?
    Let's find the answer in this video. Enjoy!
    --
    Golang Dojo is all about becoming Golang Ninjas together. You can expect all kinds of Golang tutorials, news, tips & tricks, and my daily struggles as a Golang developer. Make sure to subscribe if you look forward to such content!
    Get Your Golang Cheat Sheet! - golangdojo.com/cheatsheet
    Git repos & notes - golangdojo.com/resources
    Golang Basics - • Golang Basics - Instal...
    Golang Informative - • How much do Golang dev...
    --
    Timestamps
    0:00 Intro
    1:41 What is Inheritance?
    4:09 What is Composition?
    5:16 How Go Uses Composition
    7:20 Outro
    --
    #golang #goprogramming #golangdojo
  • Наука та технологія

КОМЕНТАРІ • 37

  • @GolangDojo
    @GolangDojo  2 роки тому +3

    📝Get your *FREE Golang Cheat Sheet* -
    golangdojo.com/cheatsheet

  • @ekremkamaz1490
    @ekremkamaz1490 2 роки тому +23

    Here is a trick. For example you can remove the name of walkable inside of duck struct (not "w walkable" just "walkable"). Than you can access walkable methods without redefining it like duck.w.walk(). Then when creating a new struct you will gonna use type name as a attribute name. (duck{walkable:walkable{}})

  • @user-vj4rn3uw1v
    @user-vj4rn3uw1v 2 місяці тому +1

    Well, composition is really common to use even in languages like Python. And this is really good if you replace deep inheritance tree to some composition decision. But if inheritance is not deep than it is really useful and readable, because all methods aggregate into single object. When you have a lot of small independent functions which actually very dependant this is less intuition way, I think.

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

    Awesome explanation, but icing on the cake is the music at the end of the video, I loved it, thank you for sharing your knowledge

  • @dranon0o
    @dranon0o 2 роки тому +9

    It's so far the best explanation on that topic
    Thanks :)

  • @rz5541
    @rz5541 Рік тому +1

    Very helpful videos man, well explained and clear!

  • @CommonWebDev
    @CommonWebDev 2 роки тому +1

    Thanks. Your exlain was wonderful. I love the capacity of composition. I use it in Javascript too...

  • @pashtolyrics7980
    @pashtolyrics7980 Рік тому +1

    Best explanation ever Thanks a lot man !!

  • @anilrajpal963
    @anilrajpal963 2 роки тому +1

    This channel will make it to Million subscriber club.

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

    Perfect explanation! 💯%

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

    Thanks, I've been learning golang a month and still a lot of it confuses me. Very helpful

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

    Thank you!

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

    Awesome!

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

    Tips to understand large code projects?

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

      1. Make sure you really understand the domain, the underlying business problems the system is trying to solve.
      2. Choose one simple action and explore how the system handles it end to end, e.g. "how does a user changing a value in the UI update their address in the database?" Ask your team questions when you get stuck.
      3. Repeat step 2 a few times until the high-level patterns start to show themselves. There will be patterns.
      4. Accept that no one know everything about a large codebase (or at least it's incredibly rare).

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

    This was very good video. Can you make videos on building server api with Echo framework. And If you can Please try to make real world example and follow Good Architecture. I know i am asking too much , but i am facing problems in implementing a Hexagonal Architecture/Port and Adapter. I have been learning a lot from this channel . Thank you very much .

  • @RobertLugg
    @RobertLugg Рік тому +2

    When would you use interfaces versus inheritance or composition?

    • @mwatkins0590
      @mwatkins0590 Рік тому +2

      so for instance if when you call duck.walk you want it to say "waddling" instead of "walking" you would need to define "walkable" as an interface. then you would attach "walk" as a function directly onto duck and you would define the behavior in the duck struct.
      So the reason you would do this is if the "child" struct that you want to attach a type of behavior to needs to specifically define its own version of that behavior. Instead you would use the composition as in the video if everything doing that behavior does it in the same way.
      in summary - interface if implementers need to define the logistics of how that method is performed (but you want to stuff these abstractions together in a same collection or something still which uses a func with the same function signature), composition if you want to define the behavior once and all things containing it perform the function in the exact same way and dont need to customize it.

  • @adrianrevill7686
    @adrianrevill7686 Місяць тому

    I can follow it all except what is the a...: in the Println?

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

    The closing music is exciting..

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

    Good video, really interesting channel maybe coding streaming soon?

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

    Can someone please explain to me what the difference between inheritance and struct imbedding is? It seems the same if not similar to me.

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

    Inheritance is broken and I like how go only allowing for composition. In the book design patterns by the gang of 4 they explain what's the problem with inheritance.

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

    So tailwindcss instead of sass (sort of)

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

    How you do dependency injection?

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

      create interface and make those interface as a return value of a struct instantiation

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

    Did you heard of javascript bun
    Compare it with golang

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

    thank you, yes a dog can walk

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

    I hate the language that don't have proper structure and rules and makes fusion to blast mind.

  • @Onlyindianpj
    @Onlyindianpj 2 роки тому +1

    Man you really need to work on pronunciation
    I hardly understood the word composition

    • @JT-oh6th
      @JT-oh6th 2 роки тому +1

      Get better headphones/speakers - his pronunciation was fine

    • @victorvondoom2350
      @victorvondoom2350 2 роки тому +1

      compared to most indian accent . better!

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

      interesting, composition sounded mostly fine to me, "object" was the harder word for me to understand.

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

    @Léo Miranda Dev in my case these things appear, because I use postman that already works and I convert to Go, then I have to use json.NewEmcoder, http.NewRequest, httpClient.Do(req), all these cases straight, How can I unit test a postman consumer to Go?

  • @theuniverse2268
    @theuniverse2268 10 місяців тому

    Composition over inheritance
    BUT FUCK composition without inheritance.

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

    Hi, can I email you , if possible can you please reply back your email address please. It's about learning and getting advice in order to get in go developer jobs.

  • @AMFLearning
    @AMFLearning 2 роки тому +1

    nice #amflearning #amflearningbydoing