Object oriented programming

What is OOPS?

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

OOP meaning “Object Oriented Programming” is a popularly known and widely used concept in modern programming languages like Java.

Objects and classes:

  • Classes – the definitions for the data format and available procedures for a given type or class of object; may also contain data and procedures (known as class methods) themselves, i.e. classes contain the data members and member functions
  • Objects – instances of classes

Each object is said to be an  instance of a particular class . Procedures in object-oriented programming are known as  methods; variables are also known as  fields, members, attributes, or properties. This leads to the following terms:

  • Class variables [TBD] – belong to the class as a whole; there is only one copy of each one
  • Instance variables or attributes [TBD] – data that belongs to individual objects; every object has its own copy of each one
  • Member variables  [TBD] – refers to both the class and instance variables that are defined by a particular class
  • Class methods [TBD]– belong to the class as a whole and have access to only class variables and inputs from the procedure call
  • Instance methods [TBD]– belong to individual objects, and have access to instance variables for the specific object they are called on, inputs, and class variables

Inheritance:

Inheritance is one of the Basic Concepts of OOPs in which one object acquires the properties and behaviours of the parent object. It’s creating a parent-child relationship between two classes. It offers robust and natural mechanism for organizing and structure of any software.

Encapsulation:

  • Technically, in encapsulation, the variables or the data in a class is hidden from any other class and can be accessed only through any member function of the class in which they are declared.
  • In encapsulation, the data in a class is hidden from other classes, which is similar to what data-hiding does. So, the terms “encapsulation” and “data-hiding” are used interchangeably.
  • Encapsulation can be achieved by declaring all the variables in a class as private and writing public methods in the class to set and get the values of the variables.

Abstraction:

Abstraction is one of the OOPs Concepts in Java which 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. Lets understand this one of the OOPs Concepts with example, while driving a car, you do not have to be concerned with its internal working. Here you just need to concern about parts like steering wheel, Gears, accelerator, etc.

Polymorphism:

It refers to the ability of object-oriented programming languages to differentiate between entities with the same name efficiently. This is done by Java with the help of the signature and declaration of these entities

Polymorphism in Java is mainly of 2 types: 

  1. Overloading
  2. Overriding 

Association:[TBD]

Association is a relationship between two objects. It is one of the OOP Concepts in Java which defines the diversity between objects. In this OOP concept, all objects have their separate lifecycle, and there is no owner. For example, many students can associate with one teacher while one student can also associate with multiple teachers.

Aggregation:[TBD]

In this technique, all objects have their separate lifecycle. However, there is ownership such that child object 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:[TBD]

Composition is a specialized form of Aggregation. It is also called “death” relationship. Child objects do not have their lifecycle 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.

Reference:

https://www.geeksforgeeks.org/object-oriented-programming-oops-concept-in-java/

https://www.w3schools.com/java/java_classes.asp

https://en.wikipedia.org/wiki/Object-oriented_programming

https://www.guru99.com/java-oops-concept.html

Leave a comment

Design a site like this with WordPress.com
Get started