Object Oriented Programming

 Object Oriented Programming

Object Oriented Programming(OOP) is a programming concept that works on the principles of abstraction, encapsulation, inheritance, and polymorphism. It allows users to create the objects that they want and then, create methods to handle those objects. Basic concept of OOP is to create objects, re-use them throughout the program, and manipulate these objects to get results.



 

Class

Class is a group of similar entities. It is only an logical component and not the physical entity. 

Ex: if you have a class called "Racing Cars" it could have objects like Subaru, Nissan, Honda, BMW, etc. Its properties(data) can be price, max_speed, horse_power of these cars. While methods maybe performed with these cars are driving, reverse, braking etc.


Object

An object can be defined as an instance of a class, and there can be multiple instances of a class in a program. An Object contains both the data and the function,which operates on the data 

Ex:chair,bike,marker,pen,table,car,etc.


Inheritance

In inheritance an object acquires the properties and behaviors of the parent object. It's creating a parent-child relationship between 2 classes.

 

Polymorphism 

Polymorphism refers to the ability of a variable, object or function to take on multiple forms. Example: in English, the verb run has a different meaning if you use it with a laptop, a foot race, and business. Here, we understand the meaning of run based on the other words used along with it. In polymorphism also a similar concept is followed.


Abstraction

An abstraction is an act of representing essential features without including background details. It is a technique of creating a new data type that is suited for a specific application. Example: While driving a car, you do not have to be concerned with its internal working. Here you just need to concern about parts used in the driving process like, steering wheel, Gears, accelerator, etc.


Encapsulation

Encapsulation is an OOP technique of wrapping the data and code. In this concept, the variables of a class are always hidden from other classes. It can only be accessed using the methods of their current classes. Example: in school, a student cannot exist without a class.

 

Association

It is a relationship between two objects. It defines the diversity between objects. In this OOP concept, all object have their separate life-cycle but there is no owner. Example: many students can associate with one teacher while one student can also associate with multiple teachers.


Aggregation

Objects present within this technique have their separate life-cycle. and there is ownership such that child can;t belong to another parent object. For example consider class/objects department and teacher. Here, a single teacher can't belong to multiple departments, but even if we delete the department, the teacher object will never be destroyed.


Composition

Composition is a specialized form of Aggregation. It is also called "death" relationship. Child objects do not have their life cycle so when parent object deletes all child object will also delete automatically. For that, let's take an example of House and rooms. Any house can have several rooms. One room can't become part of two different houses. So, if you delete the house room will also be deleted.


Advantages of OOP

OOP offers easy to understand and a clear modular structure for programs.

Objects created for Object-Oriented Programs can be reused in other programs. Thus it saves significant development cost.

Large programs are difficult to write, but if the development and designing team follow OOPs concept then they can better design with minimum flaws.

It also enhances program modularity because every object exists independently. 


Happy Coding!

Comments

Popular posts from this blog

cURL (Client Uniform Resource Locator)

JDK Version Differneces