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 don't really want to rain on your parade, yet one of my biggest problems when learning OOP was the real-world-examples. You almost never model cars, or shelves, or animals that way.
And once you delve deeper into OOP basically everybody is like "beware of inheritance" because the inheritance tree is not very flexible (it creates strongly coupled classes) and you shoot yourself in the foot very easily.
And while I would not call it evil, there are almost always more fitting patterns available for your polymorphism besides inheritance.
This leads to the strange fact that inheritance is one of the earliest thing one learns in OOP, yet it's the one I use the rarest. -
GIS-Jedi4224y@k0pernikus I can see your point, however I am a visual learner and as a beginner this was simple my way of understanding the concept of OOP for myself, that I thought would be funny to share 😊 .
-
iiii90854yI'd say it should be an interface on the left, and specific implementations of the interface on the right.
-
Pretty odd to name a 2D array class "Shelving".
Normally, that sort of thing is called a matrix (fixed dimensions) or table (fixed column count, fixed or variable amount of rows/records). -
This one's actually pretty good and very much feasible IMO, as long as you don't define a "furniture" superclass that shelving and chair inherit from, because that appears nowhere outside OOP examples.
-
LLAMS36644y@Oktokolo lol what.
what part of that diagram has anything to do with matrices. Its Ikea furniture dude. -
If you're a business that sells shelving and you allow users to filter the available stock by various parameters it's entirely possible that you'd have this class, at least as a DTO.
-
In fact this is exactly what the frontend should receive, plus some standard properties from the Product superclass like image, price, availability.
-
@LLAMS
Never heared about a furniture library. Is it one of these hipster material design widget toolkits? -
I get that you use the graph for visual learning and I gave you +1 for it.
But you have to realize that you are modelling *inheritance*. It's an aspect allowed by OOP. Yet OOP !== Inheritance. And inheritance almost always has better alternatives.
I like to think of OOP as one way of dealing with the problem of mutability while avoiding a global state. You encapsulate your mutable states and you abstract the usage from its implementation.
(One of the first rookie's mistake in OOP is that everything is public. Or if it isn't, every properly will have public setters. A complete maddening antipattern. Often showcased in those oop inheritance examples.)
Interfaces and composition are so much more important concepts to understand when trying to grog OOP.
Recently, I delved into functional programming more and also noted how it's affected the way I write OOP code. If I can make a method pure, it will be and I embrace immutability wherever I can. -
It's okay @GIS-Jedi
Only thing that tempts me...
A class is not a template. Yeah.
I know I'm old and grumpy - but template is a very restrictive term, associated with assumptions that might be very wrong later.
Description, among other things, for creating kallax objects...
The "among other things" might sound stupid - but it prevents thinking of a class as only a template for <one specific thing>. -
LLAMS36644y@k0pernikus Do you just love to flex your ego or something?
Most of what you are saying may be true but is pretty incomprehensible to a beginner.
At best its a wall of text that they cant penetrate. At worst it makes them feel like they know nothing at a crucial stage of their learning where they are just starting to grasp things.
I hate this about our industry.
Also you might wanna look at the diagram again. Its not even modelling inheritance. Its showing the relationship between a class and an object. Check you actually know what the intention of the post is before you mansplain it off the edge of a cliff.
uuuggghhhhhh
okay </rant> -
nibor48134yI quite like this, it shows instantiation of objects of the class. There's no inheritance in there, which would probably just confuse.
You could potentially expand it by having one or more interfaces that the Kallax class implements, such as a shelf interface maybe?
Also you could add several instances (objects) with the same property values, to show that each object exists in it's own right (takes memory space, or space in the vast IKEA warehouse), for example show several black, 6 shelf objects stacked. -
hjk10156964y@k0pernikus I see 0 inheritance in this example. I like the blueprint analogy better for the reason you state. The OOP abstraction methods should not be tied to real world.
@iiii a storable interface is nice when you actually get more of these classes or you need to inject it in something that uses it. If not it's just complexity.
I'm a huge fan on interfaces but let's have simplicity first. @GIS-Jedi did a good job illustrating object instantiation from a class. How to use them wisely should also be taught and is almost always left out of school classes. -
GIS-Jedi4224yI am happy that the diagram has prompted a lot of conversation and appreciate the feedback that a lot of you have offered. However, I wasn't posting it for that reason, I simply thought it was amusing as an example seeing as most "real life" examples given in education are "dogs bark, cats meow, but all animals speak".
I was posting to Devrant as it was meant to be fun, rather than to Stack Overflow, yet I have met the same amount of explaining as I would have there 🤦♀️. I wasn't looking to show inheritance, I would use a different illustration for that, encapsulation and polymorphism. It's just a simple, how are object related to classes.
Either way, if anyone can think of a better visual example, why not have some fun with it and post something, if you want to throw inheritance into the mix that's okay too! 😊 -
@GIS-Jedi Sorry for that. I misread your graph on that part and argued against a strawman of my own creation. I wanted to give feedback and I like to apologize if my wording was too strong.
-
@LLAMS You know what I hate about our industry?
The lack of ability to recieve feedback and while giving it, the lack of taking a good-reasons approach.
Did I make a mistake in parsing the image. Yes I did and from that misconception on I completely missed the point. I can see that and I do feel sorry for that. You could have pointed that out like the others who kindly did it.
Yet why do you assume I wrote what I have written simply from a ego-flexing point and take offense? Why do you have to take a moral highground?
I referenced my very own struggle as a beginner when trying to grasp OOP myself. I did not intend to block somebody on their path but pointing out where I hit a confusing block in the way OOP is commonly taught in hopes they can avoid that confusion from the very beginning. -
hjk10156964y@GIS-Jedi you did good! I found it a funny way to look at it. Will show it to my ikea loving girl.
It's definitely better than the beaten to death animal example (that usually has inheritance and has @k0pernikus all worked up). Has potential to be expanded with an interface, transport etc. Can make an entire manual (no tools required) out of it!
Related Rants
My attempt at illustrating OOP 😂
random
ikea
oop
kallax
object oriented