Object Model
Definition
The object model is the conceptual and structural framework of object-oriented programming that represents a system as a collection of objects, each having state (attributes/data), behavior (methods/functions), and identity (unique existence). It describes how objects are created from classes, how they interact with one another, and how core OOP principles such as encapsulation, abstraction, inheritance, and polymorphism are applied.
Main Content
1. Objects, Classes, and Identity
- An object is a runtime entity that represents a real-world or conceptual thing. It has:
- State: the values stored in its attributes
- Behavior: the actions it can perform through methods
- Identity: a unique existence that distinguishes it from other objects
- A class is a blueprint or template used to create objects. It defines what data and behavior the objects will have.
Example:
class Student {
String name;
int rollNo;
void display() {
System.out.println(name + " " + rollNo);
}
}
Here, Student is a class, and student1, student2 are objects created from it.
- Identity is important because two objects may have the same data but still be different entities. For example, two students may have the same name, but each student object has its own unique identity in memory.
2. State and Behavior
State
- refers to the current values held by an object’s attributes. For example, a
Carobject may have the state: color = red, speed = 60, fuel = 25.
Behavior
- refers to the operations or functions an object can perform. For example, a
Carobject may have behaviors such asstart(),accelerate(), andbrake(). -
The combination of state and behavior makes objects powerful because they model both what something is and what it does.
Example: -
A
BankAccountobject stores balance as state - It performs deposit and withdraw as behavior
- This separation helps developers design systems in a natural and organized way, where data is protected and only controlled actions are allowed.
3. Core Principles of the Object Model
Encapsulation
- : Bundling data and methods together inside one unit (object/class) and restricting direct access to internal data. This protects the object from accidental misuse.
Example: balance in a bank account should not be changed directly; it should be changed through
deposit()orwithdraw().
Abstraction
- : Showing only essential details and hiding unnecessary complexity. Users of the object need to know what it does, not how it does it.
Inheritance
- : Creating a new class from an existing class so that the new class can reuse and extend its features.
Example:
SavingsAccountcan inherit fromBankAccount.
Polymorphism
- : One interface, many forms. The same method name can behave differently depending on the object.
Example:
draw()may work differently forCircle,Rectangle, andTriangle.
Working / Process
- Identify the real-world or logical entities in the problem domain.
- Convert each entity into a class and create objects with appropriate attributes and methods.
- Define relationships and interactions among objects, then use OOP principles to make the design flexible and reusable.
Advantages / Applications
- Helps in modeling real-world systems in a natural and understandable way
- Improves code reusability, maintainability, and modularity
- Supports large-scale software development through clear structure and object interactions
Summary
- The object model represents a program as interacting objects with data and behavior.
- It is built using classes, objects, identity, state, and behavior.
- It supports encapsulation, abstraction, inheritance, and polymorphism.