Design a Package class
Problem Statement
Design a Package class that represents a physical parcel in a delivery or logistics system (like Amazon, FedEx, or DHL).
Each package moves through various stages of shipment — from creation, pickup, transit, and delivery — and contains information such as sender, recipient, dimensions, weight, tracking status, etc.
The goal is to model the Package class and its interactions cleanly using object-oriented design.
🎯 Goal
Design a class (or set of classes) that can:
✅ Functional Requirements
Package Creation
Status Tracking
1
2CREATED → PICKED_UP → IN_TRANSIT → OUT_FOR_DELIVERY → DELIVERED → RETURNEDShipping Type & Cost
Standard, Express, or Overnight delivery.
Delivery Events
Error Handling
⚙️ Non-Functional Requirements
🧱 Key Classes to Design
ClassResponsibility
Package
Represents the parcel; holds core info, current status, and history.
Address
Represents a location (street, city, state, pincode, country).
Person
Represents sender/receiver details (name, contact).
ShipmentType (enum)
Represents types of shipping (Standard, Express, Overnight).
PackageStatus (enum)
Represents delivery state (CREATED, PICKED_UP, etc.).
ShipmentEvent
Logs each change in status with timestamp and location.
CostCalculator
Calculates total cost based on weight and shipment type.
🧩 Example Class Relationships
1
2Package
3 ├── trackingId
4 ├── sender (Person)
5 ├── recipient (Person)
6 ├── sourceAddress (Address)
7 ├── destinationAddress (Address)
8 ├── weight
9 ├── dimensions (length, width, height)
10 ├── shipmentType (STANDARD / EXPRESS / OVERNIGHT)
11 ├── status (PackageStatus)
12 ├── List<ShipmentEvent>
13 ├── cost
14
15ShipmentEvent
16 ├── status (PackageStatus)
17 ├── timestamp
18 ├── location
19 ├── remarks🔄 Example Flow
1
2new Package(sender, recipient, addresses, weight, EXPRESS)
3→ Status = CREATED1
2updateStatus(PICKED_UP)
3→ Event logged with timestamp and location1
2updateStatus(IN_TRANSIT)1
2updateStatus(DELIVERED)
3→ Final cost calculated🧪 Example Input / Output
Input:
1
2Package: 2 kg, EXPRESS delivery
3From: Mumbai
4To: DelhiOutput:
1
2Tracking ID: PKG1029
3Status: PICKED_UP
4Estimated Delivery: 1 Day
5Total Cost: ₹180🧠 Possible Extensions
✅ Final Summary:
Design a Package class that:
Focus on clean class structure, valid state transitions, and reusable components.