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 - Наука та технологія
📝Get your *FREE Golang Cheat Sheet* -
golangdojo.com/cheatsheet
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{}})
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.
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
It's so far the best explanation on that topic
Thanks :)
Very helpful videos man, well explained and clear!
Thanks. Your exlain was wonderful. I love the capacity of composition. I use it in Javascript too...
Best explanation ever Thanks a lot man !!
This channel will make it to Million subscriber club.
Perfect explanation! 💯%
Thanks, I've been learning golang a month and still a lot of it confuses me. Very helpful
Thank you!
Awesome!
Tips to understand large code projects?
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).
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 .
When would you use interfaces versus inheritance or composition?
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.
I can follow it all except what is the a...: in the Println?
The closing music is exciting..
Good video, really interesting channel maybe coding streaming soon?
Can someone please explain to me what the difference between inheritance and struct imbedding is? It seems the same if not similar to me.
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.
So tailwindcss instead of sass (sort of)
How you do dependency injection?
create interface and make those interface as a return value of a struct instantiation
Did you heard of javascript bun
Compare it with golang
thank you, yes a dog can walk
I hate the language that don't have proper structure and rules and makes fusion to blast mind.
Man you really need to work on pronunciation
I hardly understood the word composition
Get better headphones/speakers - his pronunciation was fine
compared to most indian accent . better!
interesting, composition sounded mostly fine to me, "object" was the harder word for me to understand.
@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?
Composition over inheritance
BUT FUCK composition without inheritance.
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.
nice #amflearning #amflearningbydoing