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.
Coupling in Object-Oriented Design
Section titled “Coupling in Object-Oriented Design”Tight Coupling
Section titled “Tight Coupling”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.
Loose Coupling
Section titled “Loose Coupling”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.
The OOAD Process
Section titled “The OOAD Process”The process of Object-Oriented Analysis and Design involves investigating the objects that constitute a system and determining how they interact.
Key Steps
Section titled “Key Steps”- Identify the objects in a system
- Define relationships between objects
- Establish the interface of each object
- Create a design that can be converted to executables using OO languages
Unified Modeling Language (UML)
Section titled “Unified Modeling Language (UML)”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.
Types of UML Diagrams
Section titled “Types of UML Diagrams”There are 14 different kinds of UML diagrams, classified into two main groups:
Structural UML Diagrams
Section titled “Structural UML Diagrams”| Diagram Type | Purpose |
|---|---|
| Class Diagram | Describes structure and behavior in use cases, providing a conceptual model in terms of entities and their relationships |
| Component Diagram | Shows how components are organized and their dependencies |
| Object Diagram | Shows a snapshot of objects and their relationships at a specific time |
| Package Diagram | Shows dependencies between packages |
Behavioral/Interaction UML Diagrams
Section titled “Behavioral/Interaction UML Diagrams”| Diagram Type | Purpose |
|---|---|
| Use Case Diagram | Describes user scenarios and illustrates the functionality provided by the system |
| Sequence Diagram | Describes interactions among classes in terms of message exchange over time |
| Activity Diagram | Models the functional flow-of-control between two or more class objects |
| State Diagram | Shows the different states of an object throughout its lifecycle |
Class Diagram
Section titled “Class Diagram”Class Structure
Section titled “Class Structure”A class is depicted as a rectangle with three horizontal sections:
Example: Flight Booking System
Section titled “Example: Flight Booking System”Relationships Between Classes
Section titled “Relationships Between Classes”1. Association
Section titled “1. Association”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
2. Multiplicity
Section titled “2. Multiplicity”Definition: Specifies how many instances of a class can participate in a relationship.
3. Aggregation (Hollow Diamond)
Section titled “3. Aggregation (Hollow Diamond)”Example: Aircraft can exist without Airline. Books can exist without Library.
4. Composition (Filled Diamond)
Section titled “4. Composition (Filled Diamond)”Example: WeeklySchedule cannot exist without Flight. TransactionHistory cannot exist without BankAccount.
5. Generalization (Inheritance)
Section titled “5. Generalization (Inheritance)”Example: Crew, Pilot, and Admin are all Person. Dog IS-A Animal, Cat IS-A Animal.
6. Dependency
Section titled “6. Dependency”Example: FlightReservation depends on Payment. Driver uses Vehicle.
7. Abstract Class and Interface
Section titled “7. Abstract Class and Interface”Abstract Class: Identified by name in italics. Cannot be instantiated.
Implementation in Code
Section titled “Implementation in Code”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).
Dependency in Code
Section titled “Dependency in Code”A weak association where an object accepts another object as a method parameter or return type.
Example:
// Dependency: Vehicle is only used as a method parameterpublic class Driver { public void drive(Vehicle vehicle) { vehicle.accelerate(); }}
public class Vehicle { public void accelerate() { // Implementation }}Aggregation in Code
Section titled “Aggregation in Code”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:
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"); }}Composition in Code
Section titled “Composition in Code”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:
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:
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.
UML Arrow Direction
Section titled “UML Arrow Direction”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.
Relationship Hierarchy
Section titled “Relationship Hierarchy”Strength Order (Weakest → Strongest)
Section titled “Strength Order (Weakest → Strongest)”Dependency → Association → Aggregation → Composition
| Relationship | Symbol | Strength | Example |
|---|---|---|---|
| Dependency | A ..> B | Weakest | Driver (A) uses Vehicle (B) |
| Association | A --> B | Weak | Admin (A) → ParkingFloor (B) |
| Aggregation | A o-- B | Moderate | Person (A) Has-A Address (B) |
| Composition | A *-- B | Strongest | ParkingFloor (A) owns Spots (B) |
| Inheritance | A <|-- B | - | Dog (B) IS-A Animal (A) |