The Only Time You Should Use Polymorphism

  Рет қаралды 84,543

Christopher Okhravi

Christopher Okhravi

Күн бұрын

The only time you should use subtype polymorphism is when you have behavioural variation in the subtypes. I teach two university courses on object oriented programming and I see this problem a lot. Let me explain. RECOMMENDED READING:
🛠️ geni.us/k8KhT3 (Refactoring)
⭐️ geni.us/zzlx (Dependency Injection: Principles, Practices, and Patterns)
💎 geni.us/hNDE (Elegant Objects)
🏛️ geni.us/IBhtLnh (Clean Architecture)
🧩 geni.us/nlbA6 (Head First: Design Patterns)
Read my FREE book on Object Oriented Programming:
🚀 theobjectorientedway.com
Watch next:
• Always Use Interfaces
CONTENTS:
00:00 Thesis
01:16 Example 1
03:28 Example 2
06:25 Example 3
13:26 Summary

Пікірлер: 665
@user-lb6zo3bj9k
@user-lb6zo3bj9k 2 ай бұрын
Finally he remembered his password
@ChristopherOkhravi
@ChristopherOkhravi 2 ай бұрын
🤣🤣
@paultapping9510
@paultapping9510 2 ай бұрын
called it!! 😂
@himanshuyadav6672
@himanshuyadav6672 Ай бұрын
Where you were?, will you make video contunue now​@@ChristopherOkhravi
@madyogi6164
@madyogi6164 Ай бұрын
This must have been some variation in data.
@Adam-326
@Adam-326 2 ай бұрын
He randomly came back after three years! Tak! Good to see you again.
@rafael.aloizio1769
@rafael.aloizio1769 2 ай бұрын
Yessssss I'm glad he is back man, I've learned so many things important on my career because of his videos
@danielszlicht2633
@danielszlicht2633 2 ай бұрын
Love him, jest super
@pulkitprajapat7862
@pulkitprajapat7862 2 ай бұрын
OMG I can't believe this, I asked him last week on Twitter when he is coming back..and here he is. 🐐
@DerRabeKirill
@DerRabeKirill 2 ай бұрын
What are the chances he’ll stay with us for some time now 😅
@pabloescobarparis6586
@pabloescobarparis6586 Ай бұрын
@@DerRabeKirilldepends if project manager leaves him alone
@Pawemie
@Pawemie 2 ай бұрын
I like to think, that you got so annoyed by someone at work using subtype polymorphism the wrong way, that it brought you back here ;)
@ChristopherOkhravi
@ChristopherOkhravi 2 ай бұрын
I teach at a university so I read a lot of student code 😉
@tony2351992
@tony2351992 Ай бұрын
in which university do you teach I need to attend there, you're a CS legend @@ChristopherOkhravi
@BANANAS2011
@BANANAS2011 29 күн бұрын
I wish more people in your team do things in wrong way that you make more videos to teach others 😂
@arminium56
@arminium56 2 ай бұрын
Man, your notification popping up is the best thing happened in months❤, please don't disappear again :)
@EricFreedmanMusic
@EricFreedmanMusic 2 ай бұрын
literally just watched your design patten playlist, thinking why hasn't he posted for 3 years. perfect timing
@williamcory4689
@williamcory4689 2 ай бұрын
Welcome back! Got a huge amount of value out of this channel in my early days of becoming a dev
@andreaskonomis3
@andreaskonomis3 2 ай бұрын
Have been watching your Design Patterns series and the code walks videos and was always thinking if I ever wanted to have a youtube channel it would have been of this style. If only he was back. Wish granted, welcome back, so happy to see notifications from you! :DDDD
@CarlRoa
@CarlRoa 2 ай бұрын
Awesome to see you back Chris! I’ve learned a lot from your videos, and have always enjoyed hearing your perspective on things. 😎👍
@echoes675
@echoes675 2 ай бұрын
Best notification from KZbin in ages. I hope you've got more for us. 100% my favourite videos covering software development!
@culturemanoftheages
@culturemanoftheages Ай бұрын
I've never been more engaged with software engineering KZbin content. Your presentation skills are excellent.
@maurobastasini8704
@maurobastasini8704 2 ай бұрын
Great to see you again Christopher. Miss your videos of design patterns and discussions about principles. Welcome Back!!
@Michaeljamieson10
@Michaeljamieson10 2 ай бұрын
please continue have been rewatching your old stuff so glad to see this
@KlamerR69
@KlamerR69 2 ай бұрын
Welcome baaaaack!!!!!!!!! Happy to see you around after so much time! Hope you'll stay for a while, your content and way of explaining things are precious.
@barisaxo
@barisaxo 2 ай бұрын
I've been watching your playlists whilst working on my project over the last year, and this video is so relevant to what I'm currently working on, and exactly what I've been asking myself while working on my current systems. Being self taught I don't know the theory very well, so I would had never known that I was dealing with 'sub-type polymorphism'. Good to know I've been going down the right path, and also to know what it's called!
@dhruvachandra8210
@dhruvachandra8210 2 ай бұрын
Suddenly you appeared out of thin air, please be consistent. Love your content.
@maximus1172
@maximus1172 2 ай бұрын
No one told you to wait
@maxpricefield7586
@maxpricefield7586 2 ай бұрын
we aint entitled to his time
@bakaoug4g491
@bakaoug4g491 Ай бұрын
He can post whenever he feels like posting. How entitled are you. Anyway thanks for the content ignore comment like above
@Ruzi1996
@Ruzi1996 2 ай бұрын
I started watching him on thursday, fell in love in his way of teaching, and was thrilled when saw that last video was posted 3 years ago. And now he appears out of nowhere 😂 If you were giving lectures on my Uni, i wouldnt miss a single one
@rizwanfirdous
@rizwanfirdous 2 ай бұрын
Last month i was discussing with my friend about Design patterns and in that discussion i recommended him your channel. While discussing i said to him that don't know why you aren't posting any content. I was little bit worried about you. Now i am very glad to see you back. 🥳🥳🎉🎉❤❤❤
@nullset11
@nullset11 2 ай бұрын
Glad to see you're back uploading videos! Your series on design patterns were instrumental in taking another step in my career!
@muhammadhamzashujaat6767
@muhammadhamzashujaat6767 Ай бұрын
Love to see you again, I look forward to rewatching as much of your videos as possible !
@eladfeldman1152
@eladfeldman1152 2 ай бұрын
happy to see you are back! keep the content coming! learning a lot.| love the whiteboard, the editing and the why you teach :)
@r1konTheAutomator
@r1konTheAutomator 2 ай бұрын
WHOA! i started watching your pattern videos like a week ago, binging them while at the gym, while taking walks, etc. i was like "eh it's been a long time since hes posted...he was a good teacher" and then here you are!!
@artemisSystem
@artemisSystem 2 ай бұрын
Whoa, seeing you in my sub box is not something i expected today. Long time viewer of the channel, since the ramda days! Good to see you back. Your channel helped me get into functional programming, and now i'm absolutely obsessed. Do you have any plans for more FP related videos?
@sam_musey
@sam_musey Ай бұрын
I came to the comments section to share my excitement about your return. But, wow, I didn't expect there to be so many of us!
@SudhakarChintapalli
@SudhakarChintapalli Ай бұрын
Hey @Chris, it's great to see you after such a long time! I've always been a fan of the way you present content with crisp editing.
@RyanCortino
@RyanCortino 2 ай бұрын
Man, I was so happy to see your face in my feed again. Glad to have you back, your videos always helped me understand these concepts so much better.
@alexstone691
@alexstone691 2 ай бұрын
I did not expect you coming back, loved your design patterns, glad to see you're doing well!
@rickydownload
@rickydownload 2 ай бұрын
From last week I started watching your Design Pattern playlist and thinking why Chris stopped posting videos for last 3 years. To my surprise there was a notification😮. Your teaching is so great and natural, not everyone gets so easily. Keep up the Great work!
@liquidpebbles
@liquidpebbles 2 ай бұрын
Glad KZbin was smart enough to recommend your video. Glad to see you posting. Always top notch stuff.
@davidntumba2447
@davidntumba2447 2 ай бұрын
I didnt even fully read the title, I just saw the thumbnail and clicked. Welcome back good sir.
@RajivKumar-qj9nw
@RajivKumar-qj9nw 2 ай бұрын
So happy to see you back. You're the sole educator whose KZbin videos I choose to view at regular speed, even when they extend to an hour.
@chirayumishra1185
@chirayumishra1185 2 ай бұрын
Welcome back Christopher. Good to see you back 😊 Keep up the good work and make learning fun and easy. All power and good wishes ❤
@ripanpramanick425
@ripanpramanick425 2 ай бұрын
Your Design pattern playlist is the best I have ever seen on any channel/courses. It was about a year ago I started and completed the DP videos, but was disappointed to see no more , and randomly today this video pops up on my feed, very happy to see you again hopefully you will complete the rest of the patterns too 😊. I tried connecting you on LinkedIn too but it was restricted I think 😅.
@benjones1452
@benjones1452 2 ай бұрын
Welcome back, I have missed your content, it is great. Your analysis has been vital to my programming evolution, if only I'd have had teachers with your energy.
@dani2500d
@dani2500d 2 ай бұрын
Finally you are back! I enjoyed so much your design patterns playlist.
@Flutterdev6391
@Flutterdev6391 2 ай бұрын
I watch your videos and you are the first teacher whoes course i can buy without thinking about money.
@nkramachandran8500
@nkramachandran8500 2 ай бұрын
Legend is backkk!!! Good to see you, your system design videos are epic!! MASSIVE THANKS
@shreyshrivastava
@shreyshrivastava 2 ай бұрын
I don't have words to describe how happy I am to see you back.. Love your style of teaching
@shridharcs
@shridharcs 2 ай бұрын
Welcome back Chris. Have learnt a lot from your design pattern series!
@Ragnarok540
@Ragnarok540 2 ай бұрын
Thanks for your work, I got a masters in software engineering 2 years ago and your videos on the design patterns really helped me.
@vivekvishwakarma3711
@vivekvishwakarma3711 2 ай бұрын
Happy to see you upload after 3 years love the way you teach..
@kiranmahajan9067
@kiranmahajan9067 2 ай бұрын
Your teaching is the greatest and simpler....❤
@wbaloo1
@wbaloo1 2 ай бұрын
I missed your tutorials man, good to have you back!
@bryanscheetz2850
@bryanscheetz2850 2 ай бұрын
Welcome back! Your videos helped me a ton while getting my degree - good to see you're still at it!
@ChandraShekhar-by3cd
@ChandraShekhar-by3cd 2 ай бұрын
Welcome back! Please upload more videos on system design and LLD. We appreciate your effort!
@drewbruggman
@drewbruggman Ай бұрын
I didn't learn anything, but the way you described the information in the video *clarified* what I'd already known -if that makes sense. You are excellent at explaining things in very clear terms, and I appreciate that. Subbed.
@ChristopherOkhravi
@ChristopherOkhravi Ай бұрын
I'm very happy to hear that. Also, thank you for the sub. Welcome 😊
@NoahNobody
@NoahNobody 2 ай бұрын
I like this format. My ADD was trying its best to block the info, but this guy just kept going :)
@ivankulaga5516
@ivankulaga5516 2 ай бұрын
Oh hey look who's back! Thanks for the video! Ur gof patterns videos helped me a ton a few years back
@UnTizioACaso1
@UnTizioACaso1 2 ай бұрын
I missed your videos, thanks for coming back!
@mohamedsayed8697
@mohamedsayed8697 Ай бұрын
Oh my god. I used to watch your videos when I started learning programming in 2021. Right now, I have an interview with Google scheduled next week. You don't know how happy I am to see you back. Thanks for coming and welcome back :)
@ChristopherOkhravi
@ChristopherOkhravi Ай бұрын
Glad to hear 😊 Best of luck on your interview!
@hazzhaston4777
@hazzhaston4777 Ай бұрын
Welcome back! So excited to see you back! huge fan of your videos. Thank you!
@mick2386
@mick2386 2 ай бұрын
It's so good to have you back. Thank you 😊
@dkvvit
@dkvvit 2 ай бұрын
Good to see you after 3 years. I love the way you teach.
@anda8369
@anda8369 2 ай бұрын
Thanks for all of these and welcome back!
@shaunhunterit342
@shaunhunterit342 2 ай бұрын
I didn't realise you hadn't posted for three years! I've been taking a break from coding but had to watch this video! Please keep posting!
@felixjonsson4471
@felixjonsson4471 2 ай бұрын
omg great to see u again! Ur videos has helped me tremendously during my time at chalmers, and im actually now TEACHING the same course i used ur videos to pass years before! Will recommend ur channel to all my students!
@ChristopherOkhravi
@ChristopherOkhravi 2 ай бұрын
Thank you 🙏😊 And congratulations
@mobasherfasihi690
@mobasherfasihi690 6 күн бұрын
Glad that see you again, hope I can see another series also before I die. But high quality takes times, I'm really enjoying when watching your videos.
@archindar5665
@archindar5665 Ай бұрын
you did really well with this video, i was able to flip into it and out of it, while just listening and you never lost me. i now know what you put into this video and thats always nice!
@mohammadz5474
@mohammadz5474 2 ай бұрын
Welcome back ! , good decision to come back , your content is wonderful
@codewithmert
@codewithmert Ай бұрын
Thanks for sharing your valuable knowledge again. Your videos about design patterns helped me a lot when I landed my first job as a software developer. I hope 🤞 you don’t give a break anymore 😊
@Indigo00757
@Indigo00757 2 ай бұрын
No way!!! You are back! Glad to see!
@ppercipio
@ppercipio Ай бұрын
This is the first video I watch from you. It makes complete sense, no idea why I never though of it like this. Looking forward to more videos!!
@ChristopherOkhravi
@ChristopherOkhravi Ай бұрын
I'm very happy to hear. Welcome 😊
@muntder1435
@muntder1435 2 ай бұрын
it's been a very long time, nice to see again man!!
@PbPomper
@PbPomper Ай бұрын
I've really missed these talks. Welcome back!
@yamogebrewold8620
@yamogebrewold8620 2 ай бұрын
Kul att se att du är tillbaka igen! Dina förklaringar av designmönster hjälpte mig enormt under skoltiden. 👍 Man önskade att fler lärare var såhär pedagogiska.
@ChristopherOkhravi
@ChristopherOkhravi 2 ай бұрын
Tack så mycket!
@sikchungliu83
@sikchungliu83 2 ай бұрын
Welcome back! Good to watch your video again!
@nonickname1231
@nonickname1231 Ай бұрын
Previously, thank you for the knowledge, and welcome back. What I get from the explanation is: We should/must prefer to be implicit about a specific type of data that has the same structure and behavior, instead of being explicit (where we define it based on the actual concept or domain) about that type (CMIW).
@virtexamit
@virtexamit Ай бұрын
Love to see you back, hope all good at your end. You have unique way of communicating complex things, Keep making video.
@no-name2031
@no-name2031 2 ай бұрын
The man, the legend, welcome back
@NoKsMG
@NoKsMG 2 ай бұрын
Great to see you again! Love your content, the way you explain complicated things is simple and approachable, love the mustaches also 🙂
@mohamedsalama2503
@mohamedsalama2503 2 ай бұрын
Welcome Back, Great to see you after 3 years :D
@FritsvanDoorn
@FritsvanDoorn 2 ай бұрын
Hej, you are back. I have mist your videos, they have helped me so very much. Thank you for another interesting and great video.
@zfold4702
@zfold4702 Ай бұрын
Welcome back, sir. Happy to know you are still creating content.
@bryancorea678
@bryancorea678 2 ай бұрын
I was waiting for this quality content again, thank you so much !!!!
@dkk9819
@dkk9819 Ай бұрын
I just remebered your design patterns series from years ago and was looking what you were up to. Great timing.
@ChristopherOkhravi
@ChristopherOkhravi Ай бұрын
😊😊
@ChristopherOkhravi
@ChristopherOkhravi Ай бұрын
Thanks for checking in again 😊
@iulianbojinca7309
@iulianbojinca7309 2 ай бұрын
Welcome back! Thank you for this! The cliffhanger in the end...oh man, please don't let us hanging for too long
@ChristopherOkhravi
@ChristopherOkhravi 2 ай бұрын
Gotta leave some loops open 😊😊
@maayanzar
@maayanzar 2 ай бұрын
Wow man, so glad to see u again, you are an amazing teacher, please keep the quality content😊
@ramongus1996
@ramongus1996 2 ай бұрын
I'm extremely happy you are back. Thank you.
@edinguitar
@edinguitar 2 ай бұрын
bro scared me with that jump in the frame haha welcome back! Thanks for the Design Patterns series which helped me a lot!
@chetanchopra1475
@chetanchopra1475 2 ай бұрын
Your teaching is simpler and also in depth, good to see you back on youtube. Please create more good quality content !!
@SeanOchoa
@SeanOchoa Ай бұрын
Loved this video. Thank you so much for the bite-size CS training. Love your style, heart, and expertise.
@zakayothuku
@zakayothuku 2 ай бұрын
He's alive!!! Glad to have you back!
@Rhyrkon
@Rhyrkon 2 ай бұрын
Damn you're back! Thank you very much for the content!
@hamzabenarfa7425
@hamzabenarfa7425 2 ай бұрын
Thank you bro for coming back
@akashcastelino6056
@akashcastelino6056 2 ай бұрын
You're a fantastic teacher. Welcome back !!!
@TazG2000
@TazG2000 Ай бұрын
I would add a point that "variations in behavior" can also come from _outside_ the class - a class can just be a data type, without being responsible for all the ways the data will be used. Imagine an Attack subtype, EnergyAttack, which has an additional property EnergyType. Now Scratch is a base Attack instance, and Thunderbolt is an EnergyAttack (with EnergyType = Lightning). Looking at just the class definitions, you could say this is a data-only variation, but it makes sense because the change is in the data structure (an additional property), not just values. These subclasses may or may not implement variations in behavior themselves, but _allow for_ external variations by being different types: We may have many general functions that work with the Attack type, as well as some functions that accept EnergyAttack specifically and work with the EnergyType property.
@alinapostol2230
@alinapostol2230 Ай бұрын
We've been waiting for you to come back! - so WELCOME BACK ^^!
@securethebag1613
@securethebag1613 Ай бұрын
Word to mother....ur design patterns videos helped me nail an interview in 2017 🤣🤣🤣. Now I'm a Lead software engineer. Thanks
@EmpySoul
@EmpySoul Ай бұрын
Once again, you enlightened me about something that might seen implicitly known and simple but in reality a truly good software engineer needs to be absolute aware of.
@siddharthkothari007
@siddharthkothari007 2 ай бұрын
Welcome back Chris. loved this one.🙏
@ReneSteenNielsen
@ReneSteenNielsen 2 ай бұрын
WB Christopher, --- I have a very curious question: 6:55: YES, why? 7:35: You MUST have had a way simpler example at first, where you still used "IAttack"; which is sort of revealed by you forgetting to delete "Stun". I personally believe that you might have overthought the lesson a bit here. Despite how rational you try to justify the new super type and broader scope. As I see it, you could easily still have stuck to: "IAttack". The third example would then showcase e.g. "Attack" and "Stun". The latter could implement e.g. a timer for the duration of the stun. That would now also be accounted for as an introduction of a new behavior and the whole thing would be fairly straight forward to understand, at least in my book 🙂 Instead, I feel like, with the current approach (creating a broader super type) students could then easily start wondering - when is enough - enough? You could then arguably keep pushing the goalpost, higher and higher in responsibility, instead of keeping the example grounded where it all began... I guess this also leaves the solution vulnerable to potential constant refactor, just as the slightest requirements change regarding the architecture... I think you somewhat try to clarify for this yourself around 9:55... Maybe I'm just too caught up in the semantics or too curious... Let me know, if I misunderstood something very vital 🙂 --- Thanks!
@oleksandr.pastukhov
@oleksandr.pastukhov 2 ай бұрын
Good to see you again! Welcome back!
@Jeff-xh4sy
@Jeff-xh4sy 2 ай бұрын
I used your design pattern videos to pass my cs class last term and here you are again lol
@eugeniogonzato
@eugeniogonzato 2 ай бұрын
So nice to see you came back,thanks
@arteqppp6223
@arteqppp6223 Ай бұрын
Your knowledge is actually so precious. I love the fact that you just use concepts with whiteboard. Thank You for coming back to us, You can make a lot of us promote with your videos!
@ChristopherOkhravi
@ChristopherOkhravi Ай бұрын
Thank you very much for sharing 😊😊
@observable-compositions-1996
@observable-compositions-1996 Ай бұрын
Thanks for coming back man
@rudreshgp
@rudreshgp 2 ай бұрын
Thank you Christopher for your design pattern series. That is one of the reason I got promoted 🙏🙏🙏
@ChristopherOkhravi
@ChristopherOkhravi 2 ай бұрын
Congratulations! 🎊😊
@yveltdesamours5225
@yveltdesamours5225 Ай бұрын
Welcome back! Good to see you!
@noeldionisioparedescuevas5992
@noeldionisioparedescuevas5992 2 ай бұрын
We miss your valuable teach.
@tomthetitan101
@tomthetitan101 Ай бұрын
This is one of the most engaging software videos I've ever seen
@pecasm3436
@pecasm3436 2 ай бұрын
I am in love with this guy !!! He radiaties positivity and passion :) Glad to see u again Christopher:)
Factory Method Pattern - Design Patterns (ep 4)
27:21
Christopher Okhravi
Рет қаралды 528 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 744 М.
【獨生子的日常】让小奶猫也体验一把鬼打墙#小奶喵 #铲屎官的乐趣
00:12
“獨生子的日常”YouTube官方頻道
Рет қаралды 95 МЛН
The World's Fastest Cleaners
00:35
MrBeast
Рет қаралды 123 МЛН
Каха с волосами
01:00
К-Media
Рет қаралды 5 МЛН
Her Birthday Was Ruined 😰😩 He Created A Trap For Her🙀
00:40
Giggle Jiggle
Рет қаралды 4,1 МЛН
Top 6 Tools to Turn Code into Beautiful Diagrams
3:24
ByteByteGo
Рет қаралды 505 М.
Always Use Interfaces
8:08
Christopher Okhravi
Рет қаралды 42 М.
Why Most Programmers DON'T Last
18:56
Healthy Software Developer
Рет қаралды 219 М.
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 417 М.
ThePrimeagen Hacks My Productivity
3:30
Scott Macchia
Рет қаралды 29 М.
How Senior Programmers ACTUALLY Write Code
13:37
Healthy Software Developer
Рет қаралды 1,2 МЛН
Only Use Inheritance If You Want Both of These
9:10
Christopher Okhravi
Рет қаралды 10 М.
Depend on Abstractions not Concretions (Framework)
11:56
Christopher Okhravi
Рет қаралды 13 М.
how NASA writes space-proof code
6:03
Low Level Learning
Рет қаралды 2 МЛН
【獨生子的日常】让小奶猫也体验一把鬼打墙#小奶喵 #铲屎官的乐趣
00:12
“獨生子的日常”YouTube官方頻道
Рет қаралды 95 МЛН