Object-Oriented Design (OOD)
Definition:
Object-Oriented Design is a method of designing software based on real-world concepts, using objects that encapsulate data and behavior. It focuses on modeling a system using classes, objects, inheritance, and polymorphism.
Think of it like designing a zoo: each animal is an object with properties (name, age) and behaviors (eat, sleep), and animals of the same type share a class blueprint.
Key Concepts of OOD
-
Classes and Objects
-
Class: A blueprint for creating objects. Defines attributes (data) and methods (behavior).
-
Object: An instance of a class. Each object has its own state.
-
Example: class Car { color, speed; drive(); stop(); } → myCar = new Car()
-
Encapsulation
-
Bundling data and methods together in a class.
-
Hides internal implementation from the outside world (access via public methods).
-
Example: Private variables with public getter/setter methods.
-
Inheritance
-
Allows a class (child) to inherit properties and methods from another class (parent).
-
Promotes code reuse and hierarchical relationships.
-
Example: class ElectricCar extends Car { batteryCapacity; }
-
Polymorphism
-
Abstraction
-
Focus on essential features, hiding unnecessary details.
-
Achieved using abstract classes or interfaces.
-
Example: interface Vehicle { drive(); } → implemented by Car, Bike, etc.
Benefits of OOD
-
Modularity – System is divided into manageable objects.
-
Reusability – Classes can be reused across projects.
-
Maintainability – Changes in one class have minimal impact on others.
-
Scalability – Easy to extend system with new classes.
-
Real-world Modeling – Mirrors real-world entities, making design intuitive.
Example in Real Life
-
Class: Employee
-
Attributes: name, id, salary
-
Methods: calculateSalary(), promote()
-
Inheritance: Manager and Developer inherit from Employee
-
Polymorphism: calculateSalary() works differently for Manager and Developer.