ObjectOriented Design (OOD) System Design (original) (raw)

Object-Oriented Design (OOD) - System Design

Last Updated : 8 Dec, 2025

Object-oriented design (OOD) is a programming technique that solves software problems by building a system of interrelated objects. It makes use of the concepts of classes and objects, encapsulation, inheritance, and polymorphism to model real-world entities and their interactions. A system architecture that is modular, adaptable, and simple to understand and maintain is produced using OOD.

hierarchy_of_programming_paradigms_

Object-Oriented Design Concepts

A number of fundamental ideas are included in object-oriented design (OOD), which makes it easier to create software that is reliable, scalable, and maintainable. These are the main ideas, supported by examples and explanations.

1. Encapsulation

Encapsulation is the bundling of data (attributes) and methods (functions) that operate on the data into a single unit called a class. It restricts direct access to some of the object's components, which is a means of preventing accidental interference and misuse of the data.

Encapsulation

Encapsulation

**Example:

Consider a Car class with private attributes speed and fuelLevel and public methods accelerate(), brake(), and refuel(). The internal state of speed and fuelLevel can only be modified through these methods, ensuring controlled access.

C++ `

#include

using namespace std;

class Car { private: int speed; double fuelLevel;

public: Car() : speed(0), fuelLevel(100.0) {}

void accelerate(int amount) {
    speed += amount;
    fuelLevel -= amount * 0.1;
}

void brake() {
    speed = 0;
}

void refuel(double amount) {
    fuelLevel += amount;
}

void display() {
    cout << "Speed: " << speed << ", Fuel Level: " << fuelLevel << endl;
}

};

int main() { Car myCar; myCar.accelerate(10); myCar.brake(); myCar.refuel(20); myCar.display(); return 0; }

`

Output

Speed: 0, Fuel Level: 119

2. Abstraction

Abstraction involves hiding the complex implementation details and showing only the essential features of the object. This helps in managing complexity by allowing the designer to focus on the interactions at a higher level.

Abstraction

Abstraction

**Example:

An Animal class can represent general properties and behaviors common to all animals without detailing the specific implementation for each type of animal.

C++ `

#include #include

using namespace std;

class Animal { public: virtual string makeSound() const = 0; // Pure virtual function };

class Dog : public Animal { public: string makeSound() const override { return "Bark"; } };

class Cat : public Animal { public: string makeSound() const override { return "Meow"; } };

int main() { Animal* dog = new Dog(); Animal* cat = new Cat();

cout << dog->makeSound() << endl;
cout << cat->makeSound() << endl;

delete dog;
delete cat;
return 0;

}

`

3. Inheritance

Inheritance is a mechanism where a new class inherits properties and behaviors (methods) from an existing class. This promotes code reuse and establishes a natural hierarchy between classes.

Inheritance

Inheritance

**Example:

A Vehicle class can be a parent class with common attributes like make and model, and child classes like Car and Bike can inherit these attributes and have additional specific properties

C++ `

#include #include

using namespace std;

class Vehicle { protected: string make; string model;

public: Vehicle(std::string make, std::string model) : make(make), model(model) {} };

class Car : public Vehicle { private: int num_doors;

public: Car(string make, string model, int num_doors) : Vehicle(make, model), num_doors(num_doors) {}

void display() {
    cout << "Make: " << make << ", Model: " << model << ", Doors: " << num_doors << endl;
}

};

class Bike : public Vehicle { private: string type_bike;

public: Bike(string make, string model, string type_bike) : Vehicle(make, model), type_bike(type_bike) {}

void display() {
    cout << "Make: " << make << ", Model: " << model << ", Type: " << type_bike << endl;
}

};

int main() { Car myCar("Toyota", "Corolla", 4); Bike myBike("Yamaha", "MT-07", "Sport");

myCar.display();
myBike.display();
return 0;

}

`

Output

Make: Toyota, Model: Corolla, Doors: 4 Make: Yamaha, Model: MT-07, Type: Sport

**4. Polymorphism

Polymorphism allows objects of different classes to be treated as objects of a common super class. It enables a single interface to represent different underlying data types and allows methods to use objects of various types.

Polymorphism

Polymorphism

**Example:

Both Dog and Cat classes inherit from Animal and implement the make_sound method. A function can take an Animal object and call make_sound, regardless of whether it's a Dog or Cat.

C++ `

#include #include

using namespace std;

class Animal { public: virtual string makeSound() const = 0; // Pure virtual function };

class Dog : public Animal { public: string makeSound() const override { return "Bark"; } };

class Cat : public Animal { public: string makeSound() const override { return "Meow"; } };

void animalSound(const Animal& animal) { cout << animal.makeSound() << endl; }

int main() { Dog dog; Cat cat;

animalSound(dog); // Outputs: Bark
animalSound(cat); // Outputs: Meow
return 0;

}

`

**5. Composition

Composition is a design principle where a class is composed of one or more objects of other classes, rather than inheriting from them. This promotes flexibility and reusability.

Composition-(1)

Composition

**Example:

A Library class can be composed of Book objects. Instead of inheriting from Book, the Library class contains multiple Book instances.

C++ `

#include #include #include

using namespace std;

class Book { private: string title; string author;

public: Book(string title, string author) : title(title), author(author) {}

string getTitle() const {
    return title;
}

std::string getAuthor() const {
    return author;
}

};

class Library { private: vector books;

public: void addBook(const Book& book) { books.push_back(book); }

void listBooks() const {
    for (const auto& book : books) {
        cout << book.getTitle() << " by " << book.getAuthor() << endl;
    }
}

};

int main() { Book book1("1984", "George Orwell"); Book book2("To Kill a Mockingbird", "Harper Lee");

Library library;
library.addBook(book1);
library.addBook(book2);
library.listBooks();
return 0;

}

`

Output

1984 by George Orwell To Kill a Mockingbird by Harper Lee

By understanding and applying these core concepts, developers can create well-structured, maintainable, and efficient software systems.

Design Patterns in Object-Oriented Design (OOD)

Design patterns in Object-Oriented Design (OOD) are proven solutions to common problems that arise in software design. These patterns provide templates that help to structure code in an efficient and maintainable way.

Here are some of the most commonly used design patterns in OOD:

**1. Creational Patterns: Creational patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Some key creational patterns include:

**2. Structural Patterns: Structural patterns deal with object composition or structure, ensuring that if one part changes, the entire structure does not need to do so. Some key structural patterns include:

**3. Behavioral Patterns: Behavioral patterns deal with communication between objects, making it easier and more flexible. Some key behavioral patterns include:

UML Diagrams for Visualizing OOD

Diagrams created using the Unified Modeling Language (UML) are useful tools for understanding and clarifying object-oriented system structure. They serve as a blueprint, showing the interactions between many components of a system, which makes difficult concepts simpler to understand and communicate.

Here are some common UML diagrams and how they contribute to object-oriented design:

By using these diagrams, developers can make sure everyone has a clear picture of the system’s structure and behavior, making it easier to collaborate and avoid misunderstandings.

Common Challenges and Anti-Patterns in Object-Oriented Design (OOD)

While it offers strong software development concepts, object-oriented design (OOD) is not without its challenges and drawbacks. For systems to be productive and maintained, it is essential to recognize these difficulties and stay clear of typical anti-patterns.

These are a few common OOD challenges and anti-patterns:

Common Challenges in Object-Oriented Design (OOD)

1. Designing for potential future needs that may never arise, which adds needless complexity.

2. Not foreseeing future demands and modifications, which leads to an inflexible system.

3. Ensuring that encapsulation does not excessively degrade performance.

4. Determining the right level of abstraction to balance simplicity and functionality.

Common Anti-Patterns in Object-Oriented Design (OOD)