What you need to know about Object Oriented Programming

Search for a command to run...

Nice article!
I disagree with this statement:
This paradigm is based around defining “Classes” which will initialize “objects”
OO is about objects, not classes.
There are ways to implement OO without using classes and JavaScript is a great example.
JavaScript, as described by ECMAscript specification, is an:
... object-oriented programming language for performing computations and manipulating computational objects within a host environment.
However, objects are not created by class instancing.
Even though ECMAScript includes syntax for class definitions, ECMAScript objects are not fundamentally class-based such as those in C++, Smalltalk, or Java.
Nice article!
I liked very much.
I disagree with UML part. I think only code speaks the truth.
But it is just my opinion
At some point every developer has used --force and overwritten somebody else’s work unnecessarily. It’s usually not the end of the world but its easily avoidable. IMO you should never really use --force, in virtually 99.9% of cases where you need to ...

Often technical jargon can be ambiguous and mislead developers, a perfect example of this is the term “functional programming” (FP) or “Object oriented programming ” (OOP). It’s easy to assume that FP is just writing your code in a series of function...

Any application needs to access data from somewhere. Whether it’s a local db, remote db, or even a text file you probably have persisted data somewhere and how your application receives that data can differ drastically. While its looking like JSON i...

Along with “Hello World” it seems like one of the early things people stumble upon is prefix (++i), postfix (i++), and += (additional assignment) operator notation. These operators can be great tools but unfortunately they can also be a gun to shoot ...

Java, C++, Python, Ruby, and many other languages thrive on Object oriented programming (OOP) and understanding what that means is vital if you plan on using these languages professionally.
This paradigm is based around defining “Classes” which will initialize “objects”, these objects will contain the the attributes and properties you defined in the Class. Object oriented programming is a model that encourages encapsulation, abstraction, inheritance, and polymorphism.
Encapsulation: Ensuring that the internal state of a class is not unnecessarily exposed to people who will be adding to your code in the future. We can “hide” a classes state by making it private, this will ensure that it’s only accessible within the object and its methods.
TLDR; reduce complexity by never exposing state in the objects interface unless you have a good reason
Abstraction: Ensuring that the methods that you do expose are relevant to other objects/classes. A toaster is a great example of abstraction, rather then provide you a timer and temperature setting it gives you a number from 1-5 or shows you how dark the toast will be, this is a Abstraction.

There is not special keyword like “private” for this and knowing how to best abstract something is one of the most valuable skills any software developer can have.
TLDR; reduce complexity by abstracting the complexity of your code into higher level concepts.
Inheritance: One of the great productivity benefits of OOP is the ability to reuse classes in many contexts, inheritance makes this even more powerful. Languages that support OOP allow you to write a class that will be used by other classes. If your writing a class for dogs, cats, hamsters, etc you can begin by writing a “Mammal” class that has things like eat, sleep, etc that all mammals do.
TLDR; reduce complexity in individual classes by collecting common functionality in a single parent class
Polymorphism: It’s quite common that you have a several classes that share common functionality but accomplish it in different ways, for example a circle, square, and triangle all have an area but the calculation for each is different; using polymorphism you can declare a parent class where any shape that uses it must provide it’s own calculateArea method.
What does OOP have that Functional Programming doesn’t? While its true that OOP has lost some of its appeal in recent years its still one of the most wildly known and most common paradigms to find for any long standing codebase. Having a good abstraction is critical to maintainable software regardless of what paradigm you use but it just so happens that OOP makes this a key tenet.
Not all languages lend themselves well to this but if you are using a language well suited for OOP then these few steps can be helpful in writing OOP code.
If you dont know what these are watch some YouTube videos about them, they will make your object relations explicit and allow you to visualize how these abstractions are connected. A good UML diagram will help you find bad abstractions before you spend the time writing all the code.
Even if your just adding 1 class to a codebase its important to understand how the system works, knowing this will reduce the chance you write redundant code or have unintended side effects.
IMO debugging OOP code is harder then functional code and the best way to made debugging easier is to have robust testing.
Object oriented programming has gotten a bad wrap as a bad alternative to functional programming but it isn’t that black and white. They both have their place and it’s your job to knowwhen one may be the better choice.
If you enjoyed this article please consider “following” or subscribing to my newsletter.
đź‘‹ Have a great day!