An OOP Concept that all Developers Should Know.

Поділитися
Вставка
  • Опубліковано 28 тра 2024
  • This is what all developers should know.
    #java #composition
    🔥 STEF'S DEVELOPER BOOTCAMP AND MENTORING PROGRAM
    unclestef.com/
    🔥 JOIN STEF'S 'CODER'S CAREER PATHS' NEWSLETTER:
    newsletters.stefanmischook.co...
    🔥 FREE: LIZARD WIZARD KOMODO - TRANSFORMATIONAL MIND TRAINING:
    newsletters.stefanmischook.co...
    *************
    Channel Discord Server: / discord
    WEB HOST PAYS FOR YOUR WEB DESIGN TRAINING IN 2023:
    www.killersites.com/blog/2020...
    POPULAR & EASY CODING COURSES:
    Full stack web developer course: school.studioweb.com/store/co...
    Python 3 Foundations & Certification: school.studioweb.com/store/co...
    Complete Freelancer: school.studioweb.com/store/co...
    Complete Entrepreneur: school.studioweb.com/store/co...
    *************
    🦎 Lizard Wizard Course:
    school.studioweb.com/store/co...
    📚 BOOKS TO READ:
    My Beginners HTML5, CSS3: amzn.to/2wKsVTh
    … Complements Studioweb courses on HTML5, CSS3 and JavaScript.
    Refactoring: Improving the Design of Existing Code (2nd Edition) amzn.to/3o5cTbw
    HeadFirst Design Patterns: amzn.to/2LQ0Gdh
    Java Refactoring: Improving the Design of Existing Code (1st Edition) amzn.to/3a9nSsZ
    The Naked Ape:
    amzn.to/3fhS1Lj
    ✉️ STAY IN CONTACT:
    Stef's social links:
    Instagram: stefanmisch...
    Twitter: / killersites
    Stef's business channel:
    / @unclestef8239
    👉 GOOGLE REVIEW:
    g.page/studioWebedu/review?mt
    Leave a Google review about Stef.
    MY MOUSE & KEYBOARD:
    Logitech Keyboard I use: amzn.to/38jYDqE
    Logitech mouse I use: amzn.to/2IeVvBj
    SUPPLEMENTS THAT WORK AMAZING FOR ME:
    Protein Essentials Beef Gelatine Powder:
    amzn.to/2Pf52vL
    ... Healed my very bad knee. If you have joint problems, this *could do miracles for you.
    Webber Naturals 88862 Glucosamine Chondroitin
    amzn.to/3ss9WEa
    MY CAMERA GEAR:
    Godox VL150 lights: amzn.to/3lhsYZP
    Sigma 18-35 lens: amzn.to/33sRh0T
    Canon EOS C70 Cinema Camera
    Thanks!
    Stef
    #mentoring #codecourses #unclestef #codingcoach

КОМЕНТАРІ • 33

  • @chelmyaso
    @chelmyaso Місяць тому +7

    It is weird to compare this two approaches because inheritance does make branches from one root and composition does opposit thing - composes multiple things into one "root". Just use what you need when it needs to.

  • @Jollyprez
    @Jollyprez Місяць тому +6

    Except - you can ( and libraries frequently DO ) go too far, and overly-abstract the crap out of everything and you get a half-dozen classes to do the simplest things.
    I remember when objects included their own controllers. Now, you get "models" and separate "controllers" and frequently "implementations" to control the controllers. And a "facade" class to "simplify" accessing the implementations to get to the controllers to actually touch an object.
    It's crazy.

  • @ohwow2074
    @ohwow2074 29 днів тому +1

    Composition is used frequently in the standard library of C++. One example is GCC's libstdc++. And it's a huge project.

  • @wangshuntian
    @wangshuntian Місяць тому +2

    Very nicely explained! However, it depends on the context. When you have universal functions used throughout your code, you can place them in a superclass. This maximizes code reuse. Additionally, you can override methods in subclasses that require slightly different behavior while maintaining a common process or purpose.
    In comparison to inheritance, composition offers looser coupling, making it more flexible and tolerant of errors.

  • @glyakk
    @glyakk Місяць тому +2

    I see what you are saying and generally yes I do agree that you do not want to rely on inheritance to extend functionality. However it does have its place when you have objects that that share properties and methods to avoid duplication and maintenance. Just like any other tool you need to know how to use it properly. I do understand your content is generally geared toward beginners and but I do worry that people will avoid inheritance without really understanding how it’s useful.

    • @StefanMischook
      @StefanMischook  Місяць тому +2

      My comments on inheritance is a reaction to what I feel is an overuse of it. That said, it does have its place.

  • @forno_nicolas
    @forno_nicolas 29 днів тому

    Thanks!

  • @TricoliciSerghei
    @TricoliciSerghei Місяць тому +1

    Guys, everything can be used, and will be used.. If something is good or bad, depends on the situation / project you're in.
    In some projects inheritance will be the best thing you can think of.. Is composition superior, people say it is.. Is it though.. I don't have an answer after 12 years of programming, but what I know is that everything can be used if the situation calls for it. This is why you hear people say "depending on the requirements" or "depending on the project".

  • @mohammedalmislaty4723
    @mohammedalmislaty4723 23 дні тому

    I find inheritance is really good way to minimize the code base and to increase productivity , like for example i have multiple screens and i just want to change the header a little bit by adding data time the username of the logged user etc
    it will be a disaster if i have 100 screen in my system and i need to go to them one by one to do that thing !!!
    we could use inheritance in this case and make all the screens in our system inheriate a class we called screen and have in it the screen header that takes title and subtitle as parameter any way inheritance has it's use, but you should know when you need to use it
    Anything but that will make a disaster when you overuse it (inheritance) in your systems.

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

    I feel the same in big source code reps I have faced the this problem of rewriting the code

  • @federico-bi2w
    @federico-bi2w Місяць тому +2

    yes you are right...and the worst I saw was the "so called" senior change the father at the top to specify the behavior of specific children 🤣. You have to laugh in order to not cry!!!...especially when you are asked to continue in this foolishness 😑.

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

    Well if ya want to implement some kind of strategy pattern, for example abstract class FileProcessor having abstract method void process() and some other methods providing some common functionality and a bunch of child classes like CsvProcessor, PdfProcessor and so on. Then inheritance + polymorphism is yar friend, no? Perhaps this qualifies as a rare use case

  • @Keskinkilicnr1
    @Keskinkilicnr1 29 днів тому

    What I have always wondered is why does inheritance exist at all and why is it so popular?

    • @StefanMischook
      @StefanMischook  29 днів тому

      It is popular because of the first to market effect; inheritance is one of the first OOP patterns we learn, so we like it. It's basic lizard brain stuff. school.studioweb.com/store/course/lizard_wizard

  • @kjyu4539
    @kjyu4539 Місяць тому +2

    best explanation i have ever heard about why inheritance isn't good

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

    I might be wrong but I was brought up as a defensive coding measure for real life coding to, should one needs to add more parameters to a method from the parent class, polymorphs that method to prevent unforseen cascading impact to inherited class .

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

      If you want to create a structure in your app in terms of how the classes are built, I would suggest using interfaces rather than proper classes (or even abstract classes) to provide the scaffolding.

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

      @@StefanMischook One implements Interface and here polymorphism can also be applicable especially when adding new parameters on the same named method. BUT if that method has the same algorithm, the implemented classes need to rewrite the same code unless one creates an utility class thus borderlining as an anti OO pattern (i.e. might as well use functional programming then). Plus albeit least desirable Abstract Class can be used if the algorithm for that method remains the same whereby again Inheritance plays a role.

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

    "Inheritance basically sucks" 😂😂😂😂😂 Nephew Stefan, are you serious hahaha. You presented me a lot of joy. Really. :) hahaha. I don't know how to share this piece of happiness with others and you also.
    I knew you're different tech lead, but I wasn't expecting this 😅😅😅😅😅
    Is composition an alternative for inheritance?? Are good and big software written without inheritance?
    But I had some good time, after you said "it basically sucks" :))))).
    What about abstraction and polymorphism? Do they suck also 😅😅😅😅😅
    What about OOP in general uncle Stefan?
    What about lambda expressions ? Delegates? Do they suck also, I want to know your opinion.
    I wouldn't argue if you said "linus torvalds" or "Uncle Bob (SOLID)" suck, but when you say Bjarne Stroustrup is not smart guy, then I laugh 🤣 🤣 🤣 🤣

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

    Am already doing Python and at the OOP level. But I didn't see composition as an OOP principle. Why?

    • @StefanMischook
      @StefanMischook  Місяць тому +1

      It is a mid to advance level principle. It isn’t in of itself complex but you have to get deeper into development and design patterns to pick this up.

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

    That's why i like SQL, relationships between parent fields and their children are defined using foreign keys. it make your life easier so you won't need to use inheritance. unfortunatly sql is not suitable to all projects

  • @carsonjamesiv2512
    @carsonjamesiv2512 Місяць тому +1

    Nepo-babies. 🤣😂

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

    The intro go me hooked already, U. Stef. "Super nerdy"? count me in!
    Solid advice right to the end. Yes, we too suffered the fragility wrath of poorly implemented inheritance. We tried to forewarn against this approach, but the keyboard cowboy just want to flex claiming "simplicity"

  • @xxxxxx-wq2rd
    @xxxxxx-wq2rd Місяць тому +1

    Inheritance sounds tyranical.

    • @StefanMischook
      @StefanMischook  29 днів тому

      It's like living in a state managed by a bunch of nannies.

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

    Thanks for teaching me that a person that inherited money is a loser lol

  • @roddypine6077
    @roddypine6077 29 днів тому

    Totally off base on the analogies!!! so bad that you have no argument against inheritance.

    • @StefanMischook
      @StefanMischook  29 днів тому

      I do: brittle code due to fragile dependencies.