OOPs – Object Oriented Programming

OOPs by SKB web development | Sahil Rawat

What is an OOPs?

OOPs stand for “object-oriented programming“. OOPs is a programming language model organized around objects rather than “actions” and data rather than logic. In object oriented programming objects which have data related to a person or items are used the program can be written using many functional blocks the functional block contain instructions similar to procedural programming. Object oriented programming method is commonly used to develop software packages.

What is classes and objects?

classes and object are the two main aspects of object-oriented programming.

class

Example1:- Fruit

Example 2:- Car

object

apple,banana,orange,mango

volvo,audi,toyota

What is the structure of object-oriented programming?

The structure, or building blocks, of object-oriented programming include the following:

class

A class is a user-defined data type that we can use in our program, and it works as an object constructor, or a “blueprint” for creating objects. It does not consume memory at run time. Note that classes are not considered as a data structure. It is a logical entity. It is the best example of data binding. Note that a class can exist without an object but vice-versa is not possible. For Example: Consider the Class of Cars. There may be many cars with different names and brands but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range, etc. So here, Car is the class, and wheels, speed limits, mileage are their properties.

Object

An object is a real-world entity that has attributes, behavior, and properties. It is referred to as an instance of the class. It contains member functions, variables that we have defined in the class. It occupies space in the memory. Different objects have different states or attributes, and behavior. For example “Dog” is a real-life Object, which has some characteristics like color, Breed, Bark, Sleep, and Eats.

The following figure best illustrates the class and object in OOP.

Inheritance

When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.

  1. Sub class – Subclass or Derived Class refers to a class that receives properties from another class.
  2. Super class – The term “Base Class” or “Super Class” refers to the class from which a subclass inherits its properties.
  3. Reusability – As a result, when we wish to create a new class, but an existing class already contains some of the code we need, we can generate our new class from the old class thanks to inheritance. This allows us to utilize the fields and methods of the pre-existing class.

Polymorphism

When one task is performed by different ways i.e. known as polymorphism. For example: to convince the customer differently, to draw something e.g. shape or rectangle etc. Different situations may cause an operation to behave differently. The type of data utilized in the operation determines the behavior.

Abstraction

Hiding internal details and showing functionality is known as abstraction. Data abstraction is the process of exposing to the outside world only the information that is absolutely necessary while concealing implementation or background information.For example: phone call, we don’t know the internal processing. In C++, we use abstract class and interface to achieve abstraction.

Encapsulation

Binding (or wrapping) code and data together into a single unit is known as encapsulation. For example: capsule, it is wrapped with different medicines.

Advantage and disadvantage of OOPs

Advantage of OOPS

  • The concept of treating everything in OOP as an object allows for the demonstration of real-world ideas.
  • As we use the concept of encapsulation, programs are easier to test and maintain.
  • Developing classes in parallel rather than sequentially allows for faster code development.
  • OOP provides greater security due to data abstraction. The outside world cannot access the hidden data.
  • Reusability can be achieved by using classes that have already been written.

Disadvantage of OOPs

  • Designing a program with an OOP concept can be tricky.
  • A programmer needs to plan for developing a program in OOP.
  • The size of programs developed with OOP is more significant than those developed with a procedural approach.
  • Since OOP programs are larger, the execution time for these programs is also more.

What are the benefits of OOP?

  • Modularity. Encapsulation enables objects to be self-contained, making troubleshooting and collaborative development easier.
  • Reusability. Code can be reused through inheritance, meaning a team does not have to write the same code multiple times.
  • Productivity. Programmers can construct new programs quicker through the use of multiple libraries and reusable code.
  • Easily upgradable and scalable. Programmers can implement system functionalities independently.
  • Interface descriptions. Descriptions of external systems are simple, due to message passing techniques that are used for objects communication.
  • Security. Using encapsulation and abstraction, complex code is hidden, software maintenance is easier and internet protocols are protected.
  • Flexibility. Polymorphism enables a single function to adapt to the class it is placed in. Different objects can also pass through the same interface.

Leave a Comment

Your email address will not be published. Required fields are marked *