In this blog I will explain the 4 pillars of OOP and provide small examples. Small enough examples that you and I can comprehend easily.
...
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
Nice article. I'd add my 2 cents: While those features are often encountered in OO languages, they are not mandatory. For instance, GO is an OO language in some way, but it does not have inheritance.
And these pillars are not an uniquely OO feature. You'll also find them in FP (Functional Programming) languages. Except maybe for inheritance, which you will of course not find in purely FP languages (Haskell, Elm, ...) - but will find it in most of them as a result of their integration in an ecosystem (Scala, F#, ...).
Richard Feldman speaks about this in one of my favorite tech talks (specifically at 19:55, but the whole talk is really worth watching)
... That said, it does not take anything away from your article :) I just wanted to share this talk.
Can't resist to share this post from the stackoverflow blog:
If everyone hates it, why is OOP still so widely spread?
First of all thanks for a good post!
But in your encapsulation example, I see this :
It works but I suggest you either initialize them from the corresponding classes or change the variable names (dog2, dog3) to make the code clean.
Sorry, my mistake.
Your polymorphism example breaks the Liskov substitution principle. Just use composition and don't make
cow1 instanceof Dog === true
π€¦ββοΈ Did you study biology basics? πPrinciple are "stuff that helps more often than not", not pervasive absolutes on the same level as God's word. But more to the point, it would be weird to talk about inheritance as a "pillar" of oop when general practices have been recommending composition over inheritance for years.
My bad, changed it to inherit from the Animal class. You happy now professor?
You're welcome. Just didn't want to write that the example missed the point completely, that's all. π€·ββοΈ But you're definitely on a good path, keep going!
this is definition of object (from OOP)
Encapsulation
as well
Nice explanation, although as far as pillars are concerned, the main one in oop is the concept of objects. Hence the name.
Although as an interesting note, some of these pillars have been noted as broken for a while now (hence the slow ride of fp)
Thanks for sharing
Nice post