Object Oriented Programming Structure (OOPS) Concept

Object Oriented Programming is a design concept. It is nothing but a technique to design applications. Applications can be anything like web-based applications, windows, Android or iOS based. By using OOPS in PHP you can create web applications.

  1. Object – An object is an instance of a class. Anything that we see are nothing but objects. Objects can be anything like pen, car, computer, bike, mobiles, etc. If there are objects then they will have properties and behaviours which will differentiate one object from other.

    Eg:
    Take an example of a car. Car has properties (Color, Model, Brand) and behaviours(it can move forward and backward).Likewise different objects have different properties and behaviours.

    Take another example of a TV. TV has properties (Model,Brand,Color,Size) and behaviours (ON and OFF). 
    Here we are seeing that both the objects has dissimilar behaviours.

    Programming Objects are also the same as real world objects having different properties and behaviours.

  2. Class – Classes are something which defines an object.You can say Class is a blueprint of Object. Class describes all properties and behaviours of an Object. Classes define attributes and methods of the objects of its kind.

    Eg
    : 'your car' class will define that car should have color, number of door and 'your car' which is an object will have color Red and 4 doors. 'your car' is object of class car. Or in terms of programming we can say 'your car' object is an instance of the car class. So structural representation (blueprint) of your object is class. You have to create a class before you create any object.
Advantages of Object Oriented Programming

There are many advantages of OOP over the procedural programming:
  1. Re-Usability: Suppose you have created a class named Car and used at some point in an application, then you can use the same class again at another place in the same application.

  2. Easy to maintain: It is easy to maintain and modify existing code because we can create new objects just by making small differences to the existing ones.
Features of Object Oriented Programming,
  1. Here you can add data and functions easily whenever necessary.
  2. Here data is hidden and can not be accessed by external functions.
  3. Programs are divided into entities known as objects.
Entities: An entity often represents a group of people (eg children, applicants) but it can also represent a group of objects (eg textbooks), activities (eg assignments) or concepts.

Object oriented programmers must think like objects. Traditional programmers think like computers.

In order to manage different classes of a software system and to reduce complexity, there are several techniques for that. Rather you can call it as OOPS Concept.There are basically four main concepts used in OOPS. They are:
  1. Inheritance: The ability to create new class from an existing class is called inheritance. Let us understand deeply about inheritance by an example.

    Example: Let us take an example from our daily life. Suppose a person is dead, then all his belongings (it can be property, rights, etc) would be passed on to his children. In the same way it happens in the case of OOP where the Base class (also called as a parent class) has properties and methods which will be inherited by the sub class (also called sometime as a child class). Here we have seen that objects are defined by classes and classes can inherit properties and behaviours from pre-existing classes (Base Class). The resulting class is also known as sub-class or child class or derived class. The derived class can have some added properties and behaviours.


  2. Encapsulation: It means hiding data or implementation details of one module from other modules. It can also be defined as restricting access to certain properties. Encapsulation is a technique which is used for data hiding. It is helpful in reducing system’s complexity.

  3. Abstraction: It is a process of showing essential feature of the entity by hiding certain important details. It reduces code complexity. It is another good feature of oops and used to show the necessary details to the client of the object. Let us understand by an example, When you switch OFF or ON your monitor,do you know how the monitor gets ON and OFF. We don’t need to know what is happening inside the computer. Again when you drive car and change gear, does it really concern to you about the inner mechanism of gears? No, what matter to you is that then gear must be changed, that’s it. In the same way Abstraction is also a process to expose only the essential details of the object and hiding the important details which are not required by the user. This helps in re-usability of the code.

  4. Polymorphism: Polymorphism is derived by the combination of two words POLY and MORPHISM. Poly means many and Morph means slight change. Thus Polymorphism means having one name with many forms. Here we can have methods with the same name but slight change in its functionality. There are two types of Polymorphism:

      a.   Overriding: It is also called run time polymorphism. For Overriding which method will be used is determined at the run time only. The decision is made at the time of compilation.
       b.   Overloading: It is also called compile time polymorphism. Which method would be executed will be determined by the compiler. This decision is made when the code gets compiled.
Conclusion:

This article is just about the understanding of OOPs.This is not enough.The only important thing is to begin to think like objects.


Similar Articles