Defining the Object: Understanding Object Oriented Programming

Defining the Object: Understanding Object Oriented Programming

We will be looking at a very fundamental foundation of modern programming called Object Oriented Programming(OOP),this is a concept in programming that every good developer needs to be well grounded in as it shows a level of mastery and ability to use to higher order concepts in programming. In the early days of programming the major paradigm was procedural, code solutions were implemented in a step by step fashion or the computer carried out instructions following the laid down sequence, this can be quite straight forward for simple programs but as the complexity of the program increases , it gets more difficult to maintain the codebase and many times several code routines are repeated. OOP promotes the reuse of data, helping reduce development time and complexity

So what is Object Oriented Programming?

OOP is a programming language structure that groups certain data(properties) and functions(method) into singular entities called objects, it refers to how objects in real world are modelled based on their attributes and behavior, for example a real world like a car possesses several features like it has a make eg. Toyota. it has a certain color these are its attributes or properties, then it performs certain actions like it moves, it breaks to slow down or stop it movement, these actions or functions are called methods. All this features are grouped together in what is called a class, a class is basically a blueprint of an object, an object is an instance of a class or simply stated a class is to an object what a recipe is to a cake.

There are four major pillars in Object Oriented Programming

  • Abstraction

  • Encapsulation

  • Inheritance

  • Polymorphism

Abstraction: Abstraction is the hiding or shielding away of the internal implementation of an object while only showing the essential parts to the user, the information are hidden within the object definitions, they are a lot of things and tools we use that we don't understand their inward workings but we interact with them to produce certain desired results For example, there are a lot of complexities in how the engine works to drive a car but we don't have to bother ourselves with that all we do is interact with it to transport ourselves from one place to another, this concept is important in programming so that in cases where even when the internal configuration of our code changes, it doesn't have to change our outward result.

Encapsulation: Encapsulation is a means of abstraction, in a program, different objects interact with each other, encapsulation is achieved when each object keeps its state private i.e. their properties can't be changed directly except through the object's own public methods. The Car class has a fuel state which can not be tampered with except by going through its methods, like the refuel() method adds more to the fuel state while the move() method reduces it. Encapsulation enforces modularity and keeps programs less prone to errors.

Inheritance: Inheritance just like the name involves how an object can take up all or some of the properties of another object, just in the same fashion a child inherits traits and characteristics from his/her parents, Our Car class is a child of the Vehicle Class, it inherits properties like wheels, and methods like move(), a Motorcycle class also inherits from the Vehicle class, but the wheel property is unique and different from that of the Car class, inheritance helps in code reusability and reduces redundancy.

Polymorphism: Polymorphism comes from a compound greek word meaning many shapes, Polymorphism comes as a result of inheritance, OOP allows for the use of methods in various forms. Putting this simply, it refers to the use of methods in a way that a method works different for different objects using it. Both Bicycle and Car class have the move method in common, but they all implement their move action uniquely, another example we can use is a Mammal Class, this class has a method called mammalSound(). The sub-classes of Mammals could be Dogs, cats, elephants, and horses. Each of these would have their own iteration of a mammal sound (dog-barks, cat-meows).

The OOP paradigm helps in giving proper structure and shape to programs, as one is made to break up requirements into reusable classes that become the blueprints for different objects in the program. Overall, this gives room for better data structures and reusability, producing a more efficient work in the long run.

Did you find this article valuable?

Support Michael Etokakpan by becoming a sponsor. Any amount is appreciated!