70
linuxxx
9d

The moment that I finally understood OOP.

Several teachers had already given up explaining it over and over again but one classmate took a few hours to explain.

Suddenly, after a few hours, that AH-HA! moment was there!

I've done as much OOP programming as possible since then and have explained it to others who were struggling with it as well 😊

Comments
  • 19
    > Gets OOP
    > Still writes procedural (at times)

    - le me
  • 4
    I did a lot of React understood simple OOP concepts like inheritance, composition that's it.
  • 10
    @litesam126 Inheritance is most interesting concept to grasp... you dont understand it so you try to use it as much as possible... and the moment you finally understand it you start avoiding becuase of spaghetti code that it creates... rly please... if you have to use 1 method that already exists in other class, copy it... dont create chain of 7 classes inthering each other if you are not making new groundbreaking framework or something...
  • 5
    @MattSK If you want to change something and it should apply in all 7 cases then you need to make sure you do it in all of them when you copy&paste code all over the place.
  • 6
    @MattSK Looks like bad design to me
  • 2
    @linuxxx if you have time, would you consider doing an ELI5 for this? Could be of great help for people who are beginners to OOP/programming in general.
  • 2
    @dc297 A what? 😅
  • 2
    @linuxxx write it in simple terms so even a 5 yo can understand it.
  • 1
  • 4
    Favour composition over inheritance, that way spaghetti is less likely.
  • 1
    @dc297 Sure! Maybe over the weekend :)
  • 1
    Whats OOP ?
  • 2
    @Haxk20 Object Oriented Programming as far as I'm aware
  • 1
    @linuxxx Ah i see. Yes its an amazing thing when you understand it.
  • 0
    @linuxxx

    What does that mean in practice ?

    Simple examples in pseudo code would help. :-)

    I find these days, so many things I've been doing for years, have an actual name !
  • 0
    @Nanos LongStoryShort; "Object Oriented" is a mash-up or hiarchy of Classes(object) with methods(functions) and values(variables; either public/private/const/..) depending on the language you can make classes abide functionality by a trait(contract) or identify them by other specifications or other dependent classes. /pseudo code is not my thing atm/
  • 0
    Golang to the rescue!
  • 1
    @MattSK
    I don't agree with the copying. Just split your logic from your 'pure' classes (poco's) and try to generalize as much as possible.

    Basically, think in pure classes and pure functions as much as possible.

    At least that's what I tend to do.
  • 0
    @xewl

    Function is like a subroutine ?

    (Later on called a procedure..)

    Why do they keep changing the name of things. :-)
  • 0
    @xewl

    What's a class then ?
  • 1
    I agree thats why i said in complicated projects inheritance has its place, but since i work mostly as PHP freelancer i often have to work with spaghetti / legacy OOP with little to no documentation where devolpers often abused inheritance in places where Trait or Interface would make much more sense
  • 0
    @litesam126 React OOP AHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAH

    Please learn what OOP means.
  • 1
    Cat and Dog are classes of Animal. Animals can eat, sleep, play. They might do some of them differently but they all do these and (by default) let's assume they all do the same thing.

    Dogs can bark and cats can meow.

    However cats can't bark and dogs can't meow.

    So now I give you a box and tell you there's an Animal inside and you want to see if I'm telling the truth.

    What commands I can you give them that are gauranteed to be understood?
  • 0
    But then we have CatDog too... hmm.... Not sure what happens with multiple inheritance...
  • 2
    @billgates But but, I have 2 cats (real). One doesn't play. It's like play = null. You need to have a default implementation for unexisting behavior. (yes, I'm high)
  • 2
    @NoToJavaScript then one cat is LazyCat and it overrides the Cat inherited method and returns null or calls sleep()

    And that's why I said let's assume... :)
  • 1
    @billgates More like "fatCat" but I see the logic ;p Proof : Photo taken while writing this comment.
  • 0
    @Nanos still a Class? (when talking about subroutine vs function)
  • 1
    @NoToJavaScript things like playing, sleeping, ... would just be object states if you ask me.

    Make a calculated property State where you make sure the lazy cat can't return play, but the playfull one can.

    ezpz lemon squeezy
  • 1
    Reading replies here I'd say some of you should really study design patterns too. OOP is nice but creating a proper OO design is much more challenging as one should strive to do it on a conceptual level. Unfortunately, many courses teach only on implementation level or sometimes even specification level. However, it is this conceptual level that is so damn important to properly define all abstractions and generalisations. Then, you'll end up with a decent, simple OO design, where things really are maintainable and extensible and work well with minimum amount of code.
  • 0
    It took me a hot minute as well especially JUST figuring out the basics of PHP.

    Then watched Laracasts and basically Jeffrey showed me the WAY 🤓😎
  • 1
    @HisAxelency Everything is a state machine anyway !
  • 0
    Make a video about it 🤤
  • 0
    OOP: trying to model your problem domain by dividing it into stateful entities called objects - they may form complex hierarchies (inheritence, composition), exhibit complex behavior but that's not essential if you ask me.
    It's rather this:
    The objects can message each other (smalltalk), or in other words interact by calling functions. This gives the advantage from the outside that you don't need to know the details what a function call does thus potentially enabling you to build complex large systems where each component/object can be treated as black boxes receiving some inputs and performing its tasks
Your Job Suck?
Get a Better Job
Add Comment