Skip to content

Object-Oriented Analysis and Design

Object-Oriented Analysis and Design (OOAD) is a structured method for analyzing and designing systems by applying object-oriented concepts. This guide covers fundamental OO principles, UML diagrams, and the relationships between classes.

Problem: When class A directly uses class B, any method changes in class B (e.g., classB.method1()classB.method2()) require updates in class A.

PlantUML Diagram

Solution: Use interfaces to decouple dependencies. Class A refers to class B through an interface C, so changes in class B’s implementation don’t impact class A.

PlantUML Diagram

The process of Object-Oriented Analysis and Design involves investigating the objects that constitute a system and determining how they interact.

  1. Identify the objects in a system
  2. Define relationships between objects
  3. Establish the interface of each object
  4. Create a design that can be converted to executables using OO languages
PlantUML Diagram

UML is a way of visualizing and documenting a software system using a collection of diagrams, helping engineers, businesspeople, and system architects understand the behavior and structure of the system being designed.

There are 14 different kinds of UML diagrams, classified into two main groups:

Diagram TypePurpose
Class DiagramDescribes structure and behavior in use cases, providing a conceptual model in terms of entities and their relationships
Component DiagramShows how components are organized and their dependencies
Object DiagramShows a snapshot of objects and their relationships at a specific time
Package DiagramShows dependencies between packages
Diagram TypePurpose
Use Case DiagramDescribes user scenarios and illustrates the functionality provided by the system
Sequence DiagramDescribes interactions among classes in terms of message exchange over time
Activity DiagramModels the functional flow-of-control between two or more class objects
State DiagramShows the different states of an object throughout its lifecycle

A class is depicted as a rectangle with three horizontal sections:

PlantUML Diagram
PlantUML Diagram

Definition: A link between classes that need to communicate with each other.

  • Uni-directional (with arrow): Only one party is aware of the relationship
  • Bi-directional (no arrow): Both entities are aware of the relationship
PlantUML Diagram

Definition: Specifies how many instances of a class can participate in a relationship.

PlantUML Diagram

Example: Aircraft can exist without Airline. Books can exist without Library.

PlantUML Diagram

Example: WeeklySchedule cannot exist without Flight. TransactionHistory cannot exist without BankAccount.

PlantUML Diagram

Example: Crew, Pilot, and Admin are all Person. Dog IS-A Animal, Cat IS-A Animal.

PlantUML Diagram

Example: FlightReservation depends on Payment. Driver uses Vehicle.

PlantUML Diagram

Abstract Class: Identified by name in italics. Cannot be instantiated.

PlantUML Diagram

Association: A class A is associated with class B if class A contains some reference to class B anywhere inside the class (as a field, method parameter, or return type).

A weak association where an object accepts another object as a method parameter or return type.

Example:

Driver.java
// Dependency: Vehicle is only used as a method parameter
public class Driver {
public void drive(Vehicle vehicle) {
vehicle.accelerate();
}
}
public class Vehicle {
public void accelerate() {
// Implementation
}
}

A Has-A relationship where the container holds a reference to the contained object. The contained object can exist independently and may be used by other parts of the system.

Example:

Car.java (Aggregation)
public class Car {
// Car Has-A Engine (reference only)
private Engine engine;
// Engine created separately and passed in
public Car(Engine engine) {
this.engine = engine;
}
public void start() {
engine.start();
}
}
public class Engine {
private int horsePower;
public Engine(int horsePower) {
this.horsePower = horsePower;
}
public void start() {
System.out.println("Engine started");
}
}

Also a Has-A relationship, but with strong coupling. The container directly owns the contained object. If the container dies, the contained object ceases to exist.

Example:

Vehicle.java (Composition)
public class Vehicle {
private Engine myEngine; // Vehicle owns Engine
// Engine created inside constructor (composition)
public Vehicle(int horsePower) {
myEngine = new Engine(horsePower); // Created here!
}
public void start() {
myEngine.start();
}
}

Another Example:

ParkingFloor.java (Strong Ownership)
public class ParkingFloor {
// HashMap directly owns all ParkingSpot instances
private Map<String, ParkingSpot> spots;
public ParkingFloor(int capacity) {
spots = new HashMap<>();
// Create parking spots (composition)
for (int i = 0; i < capacity; i++) {
String spotId = "S" + i;
spots.put(spotId, new ParkingSpot(spotId));
}
}
}

If ParkingFloor is removed, all ParkingSpot instances are automatically removed.


Examples:

[Vehicle] ----> [Engine] (Vehicle depends on Engine)
[College] ----> [Branches] (College depends on Branches)
[College] ----> [Professor] (College depends on Professor)

The arrow shows the direction of knowledge and communication flow.


Dependency → Association → Aggregation → Composition

RelationshipSymbolStrengthExample
DependencyA ..> BWeakestDriver (A) uses Vehicle (B)
AssociationA --> BWeakAdmin (A) → ParkingFloor (B)
AggregationA o-- BModeratePerson (A) Has-A Address (B)
CompositionA *-- BStrongestParkingFloor (A) owns Spots (B)
InheritanceA <|-- B-Dog (B) IS-A Animal (A)
PlantUML Diagram