What is Object Oriented Programming?
As a software Engineer it is very important to know the meaning of Object oriented Programming. It took me a long to time to get a good grip of the concept of Object Oriented Programming. So, I decided to write about so it can help you guys who struggle like me to understand it. In this blog, I will focus on the main features and aspects of object oriented programming.
Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior.
What are objects?
Objects can be anything visible or not visible. Each Objects has it’s own attributes, and behavior. Objects are separate from one another. They have their own existence, their own identity that is independent of other objects.
What are attributes?
It’s the characteristics or the properties of the Object, like for example, in case of a cat, it’s weight & color. They describe the current state of an object. The state of one object is independent of another. Maybe you will have a cat that’s white and another one is black.
What are behaviors?
Behavior is things that the Object can do, in case of cat, It can walk. Another thing you have to notice before leaving Objects part is, Objects are nouns, they aren’t behaviors nor properties. You should differentiate of what’s actually an Object and what’s a behavior, and a property.
Now the question that comes up after knowing what object means is how do we construct these objects in our program.
Once an object is known, it is labeled with a class of objects that defines the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. Objects can communicate with well-defined interfaces called messages.
What is class?
A class is the place where you can identify the behaviors and properties of an Object. So, the properties and behavior of an Object, will be defined inside a class.
Now let’s talk about the concepts of Object Oriented Programming shown in the picture above.
Abstraction:
Abstraction means you start focusing on the common properties and behaviors of some Objects, and we automatically will discard what’s unimportant or irrelevant. Abstraction is the heart of Object-Oriented Programming, because it’s what we are doing when we make a class.
Encapsulation:
Instead of having a procedural, long program, we start to decompose our program into small reusable, manageable chunks. Encapsulation implies the idea of breaking down our program into small mini-programs; classes, where each class has a set of related attributes and behaviors.
Encapsulation also implies the idea of hiding the content of a Class, unless it’s necessary to expose. We need to restrict the access to our class as much as we can, so that we can change the properties and the behaviors only from inside the class.
Inheritance:
Abstraction is, instead of creating different classes, we can instead create one generic class that has the common, and essential properties and behavior of those classes, while Inheritance is inheriting these common properties and behaviors, so that we can create a new class, but instead of writing it from scratch, we can base it on an existing class.
Polymorphism:
Polymorphism is the state where an object can take the shape of many different forms, and lets us do the right thing at the right time. Polymorphism is the flexibility, that triggers the correct behavior.