Characteristics of OOP

Comprehensive study notes, diagrams, and exam preparation for Characteristics of OOP.

Characteristics of OOP

Definition

Object-Oriented Programming (OOP) is a programming approach in which a program is designed using objects and classes, where each object combines data members (attributes) and member functions (methods). The major characteristics of OOP include encapsulation, abstraction, inheritance, polymorphism, dynamic binding, and message passing, all of which help create modular and reusable software.


Main Content

1. Encapsulation

Encapsulation

  • means wrapping data and methods together into a single unit called a class. It protects the data from direct access by outside code and allows controlled access through methods such as getters and setters.
  • This characteristic improves data security, modularity, and maintainability. For example, in a BankAccount class, the account balance is usually kept private, and users can update it only through deposit or withdrawal methods. This prevents unauthorized or invalid changes to the data.

Encapsulation is one of the most important features of OOP because it hides internal implementation details from the user and exposes only what is necessary. This reduces complexity and helps in preventing accidental misuse of program data. It also makes the code easier to change later without affecting other parts of the program.

2. Abstraction

Abstraction

  • means showing only essential features and hiding unnecessary details from the user. It focuses on what an object does rather than how it does it.
  • It simplifies program design by reducing complexity. For example, when using a car, the driver knows how to accelerate, brake, and steer, but does not need to understand the internal engine mechanism. Similarly, in programming, an abstract class or interface can define common behavior without giving full implementation.

Abstraction is useful when a system has many details that are not needed by the user at a particular level. It allows programmers to work with high-level concepts while keeping lower-level implementation hidden. This makes software easier to understand, use, and extend.

3. Inheritance

Inheritance

  • is the mechanism by which one class acquires the properties and behaviors of another class. The existing class is called the parent class, base class, or superclass, while the new class is called the child class, derived class, or subclass.
  • It promotes code reusability and reduces redundancy. For example, a Vehicle class may contain common features like speed and fuel, while Car and Bike classes can inherit those features and add their own specific characteristics.

Inheritance helps in creating a hierarchical relationship between classes. It allows a subclass to reuse, extend, and modify the behavior of a parent class. This characteristic is especially useful in large applications because it avoids writing the same code again and again.

4. Polymorphism

Polymorphism

  • means “many forms.” In OOP, it allows the same method or operator to behave differently based on the object or context.
  • It improves flexibility and readability. For example, a method called draw() may work differently for Circle, Rectangle, and Triangle objects. Similarly, the + operator can be used for adding numbers or concatenating strings depending on the language and context.

Polymorphism is broadly categorized into compile-time polymorphism and runtime polymorphism. Compile-time polymorphism is often achieved through method overloading or operator overloading, while runtime polymorphism is achieved through method overriding. This characteristic helps developers write code that is more general, adaptable, and extensible.

5. Dynamic Binding

Dynamic binding

  • means that the method to be executed is determined at runtime rather than at compile time. It is closely related to runtime polymorphism.
  • This allows a program to decide which method implementation to use based on the actual object type. For example, if a superclass reference points to a subclass object, the overridden subclass method is called at runtime.

Dynamic binding makes programs more powerful and flexible because behavior can change depending on the actual object involved. It is commonly used in interfaces, abstract classes, and overridden methods. This feature supports advanced design principles and improves extensibility.

6. Message Passing

Message passing

  • is the process by which objects communicate with one another by sending messages in the form of method calls. One object requests another object to perform an action.
  • For example, if an Order object sends a message to a Payment object to process a payment, the communication occurs through method invocation. This improves interaction among objects and helps divide responsibilities clearly.

Message passing reflects how objects work together in a program. It encourages loose coupling, because objects do not need to know the internal details of other objects; they only need to know what methods are available. This makes the system more organized and easier to maintain.


Working / Process

1. Create classes and objects

First, identify the real-world entities in the problem domain and define them as classes. Then create objects from these classes to represent actual instances. For example, a Student class can be used to create student objects like student1 and student2.

2. Apply OOP characteristics

Use encapsulation to protect data, abstraction to hide unnecessary complexity, inheritance to reuse existing code, and polymorphism to allow multiple behaviors. These features work together to make the program structured and efficient.

3. Enable interaction and behavior execution

Objects interact with each other through message passing, and the correct method is selected through dynamic binding when needed. This allows the program to respond flexibly based on the object’s type and the situation.


Advantages / Applications

Code reusability and reduced duplication

  • : Inheritance allows common features to be reused across multiple classes, saving time and effort in development.

Better security and data protection

  • : Encapsulation hides internal data and prevents direct unauthorized access, making programs safer and more reliable.

Easy maintenance and scalability

  • : OOP makes it easier to update, debug, and expand software because code is organized into independent and manageable parts.

Summary

  • OOP is a programming approach based on objects and classes.
  • Its main characteristics are encapsulation, abstraction, inheritance, polymorphism, dynamic binding, and message passing.
  • These characteristics help create programs that are modular, reusable, secure, and easy to maintain.
  • Important terms to remember

Important terms to remember: class, object, encapsulation, abstraction, inheritance, polymorphism, dynamic binding, message passing.