Monday, June 15, 2026

1.3. Overview of object oriented principles

 Object-Oriented Programming is built on the following fundamental principles.


object :

        Any entity that has state and behavior is known as an object.

        An object has three characteristics:

        state(data/attributes): represents data (value) of an object.

        behavior(methods/functions): represents the behavior (functionality) of an object such as deposit, withdraw etc.

        identity: Object identity is typically implemented via a unique ID.

        Example, a chair, pen, table, keyboard, bike, etc.

        It can be physical or logical.

        Example: A dog is an object because it has states like color, name, breed, etc. as well as behaviors like wagging the tail, barking, eating, etc.

 

 class

  •    A class is a group of objects that has common properties.
  •  class is a template or blueprint from which objects are created.

Inheritance

  • Inheritance allows one class to acquire the properties and behaviors of another class.
  •     Inheritance is a mechanism in which one object acquires all the properties and behaviours of parent object.
  •    It provides code reusability.

 Encapsulation

        Encapsulation is a mechanism where you bind your data and code together as a single unit (class) and restricting direct access to data..

        Why Encapsulation?

o   Protects data

o   Improves security

o   Controls how data is accessed

         Data encapsulation is basically used for achieving data/information hiding i.e., security.

Real-World Example

  • 1. An ATM machine hides its internal processes. Users only interact through buttons and screens without knowing how the internal system works.
  • 2. :  a medicine capsule having different components packed as a single unit. In Java

                      Abstraction

        Abstraction refers to hiding the details and showing the essential things(features) to the user.

        If you look at the image below, whenever we get a call, we get an option to either pick it up or just reject it. But in reality, there is a lot of code that runs in the background.

        So you don’t know the internal processing of how a call is generated, that’s the beauty of abstraction.

example 1: phone call

2. When driving a car, you use the steering wheel, brake, and accelerator without knowing the internal engine mechanisms.

Polymorphism

Polymorphism allows the same method or interface to perform different actions depending on the object using it.

        Polymorphism means taking many forms, where ‘poly’ means many and ‘morph’ means forms.

         It is the ability of a variable, function or object to take on multiple forms. In other words,

        Polymorphism means more than one forms.

 Real-World Example

        A person can perform different roles:

        Teacher in a classroom.

        Parent at home.

        Customer in a store.

        The same person behaves differently depending on the situation.

Benefit

        Flexibility.

        Extensibility.

        Easier program design.


 

 




No comments:

Post a Comment

2. 0 java Class

}   Class can be defined in multiple ways Ê   A class is a blueprint for an object. Ê   A class is a user-defined data type. Ê   A cla...