Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I did a lot of React understood simple OOP concepts like inheritance, composition that's it.
-
MattSK1445y@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...
-
@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.
-
xewl41715y@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/
-
@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. -
MattSK1445yI 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
-
-
donuts238485yCat 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? -
donuts238485yBut then we have CatDog too... hmm.... Not sure what happens with multiple inheritance...
-
@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)
-
donuts238485y@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... :) -
@billgates More like "fatCat" but I see the logic ;p Proof : Photo taken while writing this comment.
-
@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 -
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.
-
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 🤓😎 -
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 -
@xewl OOP is a tool to be used when abstraction of a problem and its parts lead to a cleaner, faster and easier maintainable solution.
So throwing classes on everything is just stupid and you got it right. 😉
Btw: I found that many people who throw huge class designs upon every tiny 1+1 problem, never *really* understood OOA/OOP.
Related Rants
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 😊
rant
wk169