Unlocking the Power of OOP: A Beginner's Guide to Objects, Encapsulation, Inheritance, Abstraction, and Polymorphism

 OOPs (Object-Oriented Programming System)





This article explains the fundamental concepts of OOP and its most significant advantages



What is OOPs (Object Oriented Programming System)?

Object-oriented programming System (OOPs) is defined as a programming paradigm (and not a specific language) built on the concept of objects, i.e., a set of data contained in fields, and code, indicating procedures – instead of the usual logic-based system.



Key Concepts of OOP
To understand and use object-oriented programming, it is necessary to know the following key concepts:

1. Class
A class is a blueprint or template of an object. It is a user-defined data type. We define variables, constants, member functions, and other functionality inside a class. it binds data and functions together in a single unit. 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.


Definition 

A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It can't be physical.

2. Object
An entity that has state and behavior is known as an object e.g., chair, bike, marker, pen, table, car, etc. It can be physical or logical (tangible and intangible). The example of an intangible object is the banking system.

Points to Remember
  • Everything is an object
  • Developer manipulates objects that uses message passing.
  • Every object is an instance of a class.
  • The class contains the attribute and behavior associated with an object.

Object Definitions:

  • An object is a real-world entity.
  • An object is a runtime entity.
  • The object is an entity which has state and behavior.
  • The object is an instance of a class.

3. Encapsulation
Encapsulation is the process of grouping functions and data into a single entity. To access these data members, the member function’s scope must be set to “public,” while the data members’ scope must be set to “private.” According to this theory, an item contains all important information; only a small subset is made available to the outside world. Each object has a private class that contains its implementation and state.

Definition 
Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule which is mixed of several medicines.


4. Polymorphism

Multiple classes can use the same method name using polymorphism, which also involves redefining methods for derived classes. Compile-time polymorphism and run-time polymorphism are the two different types of polymorphism. In addition to having several forms, objects are made to have shared behaviors. To avoid writing duplicate code, the software will determine which usage or meaning is required for each time an object from a parent class is used.

Definition 
Polymorphism in Java is a concept by which we can perform a single action in different ways

Type polymorphism

There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism. We can perform polymorphism in java by method overloading and method overriding.


Overloading
If a class has multiple methods having the same name but different parameters, it is known as Method Overloading.

Overriding
If a subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java.


5. Inheritance
Inheritance is an important pillar of OOP(Object-Oriented Programming). It is the mechanism by which one class is allowed to inherit the features(fields and methods) of another class. A class that inherits from another class can reuse the methods and fields of that class. In addition, you can add new fields and methods to your current class as well

Definition

When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism

Why do we need it?
Code Reusability:
Method Overriding:
Abstraction:




6. Abstraction


Abstraction is a process of hiding the implementation details and showing functionality is known as abstraction. For example phone call, we don't know the internal processing.


Points to Remember
An abstract class must be declared with an abstract keyword.
It can have abstract and non-abstract methods.
It cannot be instantiated.
It can have constructors and static methods also.
It can have final methods which will force the subclass not to change the body of the method.









Comments

Popular posts from this blog

HTTP GET Response in Flutter

Building a Flutter Firebase Firestore CRUD App