Composition over Inheritance Explained by Games!
Ғылым және технология
Let's explore the principle of Composition over Inheritance in the context of Object-Oriented Programming (OOP) and... our favourite 8-bit video games!
This video uses metaphors and analogies from retro video games to explain the concepts of Composition and Inheritance. It highlights the advantages of Composition and why it may be a more beneficial approach. The video illustrates the principle of Composition over Inheritance, demonstrating how Composition can lead to more flexible, maintainable, and scalable code.
*What You'll Learn:*
- The key differences between Inheritance and Composition.
- Benefits of using Composition over Inheritance in your projects.
- How to be pragmatic when considering Composition over Inheritance
*Thanks:*
Thanks to @ScottYuJan and Mathias Verraes from @aardling_eu for allowing me to use their content within the video.
Scott's video:
• Organizing my Drawer w...
Tweets from Mathias Verraes mentioned in the video:
/ 1153630515104276480
/ 1153630516756852738
*Timestamps:*
0:00 Inheritance
2:11 Composition
3:18 Composition over Inheritance
7:14 When to use Inheritance?
---
Website: acairns.co.uk
Twitter: / andrewcairns
Patreon: / metaphoricallyspeaking
Discord: acairns.co.uk/discord
Substack: acairns.substack.com
#Software #Programming #Coding #SoftwareDesign #SoftwareDevelopment #OOP#ObjectOrientedProgramming
Пікірлер: 36
Prefer a written version? There is a visually-explained post on my blog: acairns.co.uk/posts/composition-over-inheritance
Fantastic video! Loved the design, graphics, editing and relatable gaming analogies throughout. Honestly, top work!
@metaphoricallyspeaking
28 күн бұрын
Much appreciated - glad you enjoyed it! :D
first time watching one of your videos, and honestly im impressed. I hope this goes well for you so that i can enjoy these videos in the fututre and so that you can improve even more the quality.
@metaphoricallyspeaking
9 күн бұрын
Thank you so much for the encouragement Tobias!
this video has so much style, I love it, keep up the good work ;)
@metaphoricallyspeaking
5 ай бұрын
Thanks Kari, appreciate it. Will try! 😅
Love the style for sure! The ad threw me for a loop though. I thought I had click out of the video by accident.
@metaphoricallyspeaking
5 ай бұрын
Unfortunately I haven't reached the dizzying heights KZread have set for monetisation and can't control when the ads show 😢 One day, maybe... Glad you enjoyed it, though!
Fantastic production quality and excellent teaching skills. Great work 👏👏
@metaphoricallyspeaking
3 ай бұрын
Thanks for the kind words, Bob - glad you enjoyed it! 😊
5:07 - oh yes, bonus point for you and scott
@metaphoricallyspeaking
5 ай бұрын
Scott is incredible. And his cinematography is at such a high standard. His drawer organiser video made me impulse-purchase a 3d printer.
I really enjoyed this one, especially the animation. Great work.
@metaphoricallyspeaking
5 ай бұрын
Thank you Stephen. Glad you enjoyed it!!
Very interesting insights, keep it up! Subscribed.
@metaphoricallyspeaking
5 ай бұрын
Thank you. I'll try! 😅 Welcome aboard! 😁
The graphic design is crazy. Easy sub earn
@metaphoricallyspeaking
4 ай бұрын
Awesome. Really glad you enjoyed it! :)
This is amazing stuff!
@metaphoricallyspeaking
3 ай бұрын
Thank you! ☺️
@pindab0ter
3 ай бұрын
@@metaphoricallyspeaking I do think there’s a market for accessible and engaging explanations of software engineering concepts. Looks like you’ve got it nailed down. Instantly subscribed!
@metaphoricallyspeaking
2 ай бұрын
@@pindab0ter Thank you. Thanks for the kind words! :D Not nailed down at all, I'm afraid. Learning a lot as I go! Haha
@pindab0ter
2 ай бұрын
@@metaphoricallyspeaking the combination of your voice, your visual style and the fact that you’re covering not beginner but intermediate topics make me look forward to you future videos!
Nice. Subscribed.
@metaphoricallyspeaking
5 ай бұрын
Appreciate it 🙌
@ThePrimeTimeagen We need your reaction. Primeagen approved or nah?
@dragonfiregaming4427
4 ай бұрын
This was a great video @metaphoricallyspeaking. Keep up the great work!
@metaphoricallyspeaking
4 ай бұрын
I would be proud and terrified - in equal measures! But, if he were to roast the video, at least I could take the low-road and mock his hair! 😁
@metaphoricallyspeaking
4 ай бұрын
Appreciate the kind words. Will certainly try! :)
Refreshing to hear real world advice, rather than the usual "always do this" nonsense. Just because a toolset has a tool, doesn't mean should or shouldn't use it. Tools are not good or bad by themselves, but using a hammer for a screw is a bad idea. Great content
@metaphoricallyspeaking
22 күн бұрын
Thanks Dave, Glad you enjoyed the video! Nothing is black and white - just lots of different shades of grey in different contexts. It's our jobs as engineers to understand the tradeoffs and make the best decision with the information we have. Also, I just recently used the hammer/nail metaphor in an article! 🤣 acairns.co.uk/posts/primitive-obsession
haven't watched the video yet, just wanted to say I (a 20yr veteran programmer) just learned about the concept a few weeks ago, though I've been an unknown advocate and practitioner of composition since being introduced to requisite oop in Java in high-school. I've carried the notion through all my projects since. always thought inheritance was a bad idea outside of strict polymorphic virtual functors where you can leverage the compiler to produce code states nessesary vs boilerplate every time a new instance is found. templating in c++ does exactly this for functional and procedural bros ok, watched the video. that last sentence "use inheritance when it exists in that domain" is basically saying the same thing. nothing in the real world actually does this. the nature of reality is to have many close but independently unique variants with- at best- partial heredity on average due to the imperfect copy problem. practically nothing is perfectly all of one other thing plus new stuff.
@metaphoricallyspeaking
4 ай бұрын
Super detailed reply. Appreciate you sharing your perspective! 🙌
2:42 int player_state = 1 // 2, 3, 100, 102020 no inheritance, just pure states )))
@metaphoricallyspeaking
15 сағат бұрын
Sometimes we might not want to merge all logic into a single class and toggle based on the state