Object Oriented Programming (OOP)


There is a good video on this subject on YouTube. Mosh Hamedani explains OOP and compares it to procedural programming. The video is called Object-oriented Programming in JavaScript: Made Super Simple.

OOP is a programming is a programming paradigm centered around objects rather than functions. The four pillars of OOP are: encapsulation, abstraction, inheritance and polymorphism.

Functional programming focuses on building a series of functions that usually take inputs, process those inputs and produce an output. Functions call other functions that call other functions and so on. A change in one function often affects another function. It works fine for small programs but can result in spaghetti code for medium or large programs. Maintenance and finding bugs can become difficult. OOP was designed to help with this challenge.

With OOP, we can combine several functions with several data pieces into a unit. The unit is an object. A class defines an object. When you instantiate an class you create an object that occupies space in memory. An object’s functions are called methods and the data elements are called properties.

Any real-world object is made up of other objects. These other objects each have their own types or variances. Also, each real-world object can do things. So, think of nouns, adjectives and verbs. A vehicle has many properties like, colour, current location, weight, make, model, size (small, compact, sedan etc.). A vehicle can do things like start engine, stop, move, accelerate, slow down, turn right, play radio and so on.