problemhardood

Object-Oriented Design for an Amazon-like Online Shopping System

HardUpdated: Oct 20, 2025

Problem

Design an object-oriented online shopping system (Amazon-like) that supports listing/selling products, searching and browsing the catalog, adding items to a shopping cart, checkout and payment, order and shipment tracking, reviews/ratings, and notifications. The system must support guest browsing, registered member purchases, sellers adding products, and administrative operations.

Diagrams and example code from the original note are preserved and reorganized to match the canonical OOD template.

Solution

1. Requirements Analysis

Functional Requirements:

  • Add/update products (sellers) and add/modify product categories (Admin).
  • Search products by name or category, view product details and reviews.
  • Guest browsing; registered members can purchase.
  • Manage shopping cart: add/remove/update item quantities.
  • Checkout flow: payment processing, order creation, shipment initiation.
  • Order lifecycle updates and shipment tracking.
  • Customers can rate and review products.
  • Send notifications for order/shipment updates.

Non-Functional Requirements:

  • Scalability: support large catalogs and high read throughput (caching/search indices).
  • Reliability: durable order processing and idempotent payment handling.
  • Extensibility: add more payment methods, shipment providers, or recommendation engines.
  • Performance: quick search and cart interactions under high concurrency.

Assumptions:

  • Product items are tracked separately from product metadata (inventory model).
  • Payment is handled via external gateways (Transaction abstraction), and shipments are tracked separately.

2. Use Case Diagram

Actors (roles and responsibilities):

  • Customer (umbrella role): Represents any user interacting with the storefront. A Customer can be either a Guest or a Member depending on authentication/registration state. -- Admin: Responsible for account and permission management and maintaining the product taxonomy — modifying product categories and high-level catalog settings. Admins act as platform moderators: they review and approve or reject seller-submitted product listings, enforce catalog policy, and perform account-level actions (block/unblock) when required.
  • Guest: Anonymous Customers who can browse and search the catalog, view product details, add or remove items in a shopping cart, and optionally register to become a Member.
  • Member: Authenticated Customers who can do everything a Guest can, plus place orders, complete checkout, and make payments.
  • Seller: Registered sellers (a different role from Member) who can create and manage product listings, update inventory for their own products, and view seller-specific analytics.
  • System: The platform components that handle background responsibilities such as sending notifications, processing shipment events, and publishing order/shipment updates.

Top use cases: Add/Update Product, Search Product, Manage Cart, Checkout & Place Order, Make Payment, Track Shipment, Send Notifications, Approve/Reject Listing

graph LR
    subgraph "Use Cases"
        UC11([Add/Update Product])
        UC12([Add/Modify product category])
        UC13([Approve/Reject Listing])
        UC14([Block/Unblock account])
        
        UC2([Search Product])
        UC3([Manage Cart])
        UC4([Checkout Shopping Cart])
        UC5([Make Payment])
        UC6([Track Shipment])
        UC7([Send Notifications for order status changes])
    end

    C[👤 Customer]
    C --> G["Guest"]
    C --> M["Member"]
    M -..-> G
    
    Seller --> UC11
    A[Admin] --> UC11 & UC12 & UC13 & UC14

    G --> UC2
    G --> UC3
    G --> UC4
    M --> UC5
    
    System --> UC6
    System --> UC7

Online Shopping System Use Case Diagram

3. Class Diagram

Core classes and responsibilities:

  • Account / Member / Guest / Admin: user identities, authentication and authorization; accounts store credentials and contact information and contain role-specific behaviour.
  • Address: shipping and billing addresses associated with accounts and orders.
  • Seller / Listing: seller accounts and their product listings; listings have states (draft, submitted, approved, rejected).
  • Catalog / Product / ProductItem / ProductCategory: product metadata, per-item inventory records, and category hierarchy.
  • ShoppingCart / CartItem: temporary selection until checkout; CartItem links a ProductItem with a desired quantity and pricing snapshot.
  • Order / OrderLog: order lifecycle, charges, and status history.
  • Shipment / ShipmentLog: shipping events, carrier info, tracking number and current status.
  • Payment / Transaction: payment processing and statuses; transactions are immutable records of payment attempts.
  • Notification: handling notifications to users (email/SMS/push) and system alerts.
classDiagram
    class Account {
        +int id
        +String userName
        +String passwordHash
        +String name
        +String email
        +String phone
        +List<Address> shippingAddresses
        +AccountStatus status
    }

    class Seller {
        +int sellerId
        +List<Listing> listings
        +getSellerDashboard()
    }

    class Admin {
        +int adminId
        +List<String> permissions
        +suspendAccount()
    }

    class Address { +int addressId +String street +String city +String state +String zip +String country }

    class Product { +int id +String name +ProductCategory category +float price +String description }
    class ProductItem { +int itemId +Product product +int quantity +String sku }
    class ProductCategory { +int id +String name +ProductCategory parent }

    class Listing { +int listingId +Product product +ListingStatus status +submit() +update() }

    class ShoppingCart { +int cartId +List<CartItem> items +addItem() +removeItem() }
    class CartItem { +int productItemId +int quantity +float priceSnapshot }

    class Order { +int orderId +OrderStatus status +List<CartItem> items +float totalAmount }
    class OrderLog { +int logId +OrderStatus status +Date timestamp }

    class Shipment { +int shipmentId +String carrier +String trackingNumber +ShipmentStatus status }
    class ShipmentLog { +int logId +ShipmentStatus status +Date timestamp }

    class Transaction { +int transactionId +float amount +PaymentStatus status +process() }
    class Notification { +send(notification) }

    Account <|-- Seller
    Account <|-- Admin
    Account <|-- Member
    Product "1" -- "1..*" ProductItem : has
    ProductCategory "1" -- "0..*" Product : contains
    Seller "1" -- "0..*" Listing : owns
    Member "1" -- "*" Order : places
    Order "1" -- "1" Shipment : ships

Online Shopping System Class Diagram

4. Activity Diagram

Activity: Checkout and Place Order

graph TD
    A[User reviews cart] --> B[Confirm address & payment]
    B --> C[Create Order]
    C --> D[Process Payment]
    D --> E{Payment success?}
    E -- Yes --> F[Mark Order PLACED & initiate Shipment]
    E -- No --> G[Mark Order PAYMENT_FAILED & notify user]
    F --> H[Send order confirmation notification]

Activity: Add Item to Cart

graph TD
    S1[Select product] --> S2[Add to cart]
    S2 --> S3[Update cart totals]
    S3 --> S4[Show cart to user]

Online Shopping System Activity Diagram

5. High-Level Code Implementation

Below are Python skeletons adapted from the original note; these follow the master-template requirement of skeleton-only code.

from enum import Enum
from dataclasses import dataclass
from datetime import date, datetime
from typing import List


class OrderStatus(Enum):
    UNSHIPPED = 1
    PENDING = 2
    SHIPPED = 3
    COMPLETED = 4
    CANCELED = 5
    REFUND_APPLIED = 6


class AccountStatus(Enum):
    ACTIVE = 1
    BLOCKED = 2


class ShipmentStatus(Enum):
    PENDING = 1
    SHIPPED = 2
    DELIVERED = 3
    ON_HOLD = 4


class PaymentStatus(Enum):
    UNPAID = 1
    PENDING = 2
    COMPLETED = 3
    DECLINED = 4


@dataclass
class Address:
    street: str
    city: str
    state: str
    zip_code: str
    country: str


class Account:
    def __init__(self, user_name: str, password: str, name: str, email: str,
                 phone: str, shipping_address: Address,
                 status: AccountStatus = AccountStatus.ACTIVE) -> None:
        self._user_name = user_name
        self._password = password
        self._name = name
        self._email = email
        self._phone = phone
        self._shipping_address = shipping_address
        self._status = status

    def reset_password(self) -> None:
        pass


class ShoppingCart:
    def __init__(self) -> None:
        self._items: List[Item] = []

    def add_item(self, item: 'Item') -> None:
        pass

    def remove_item(self, item: 'Item') -> None:
        pass

    def checkout(self) -> 'Order':
        pass


class Item:
    def __init__(self, product_id: int, quantity: int, price: float) -> None:
        self._product_id = product_id
        self._quantity = quantity
        self._price = price


class Order:
    def __init__(self, order_number: int, status: OrderStatus = OrderStatus.PENDING) -> None:
        self._order_number = order_number
        self._status = status
        self._order_date = date.today()

    def make_payment(self, payment: 'Transaction') -> bool:
        return True


class Shipment:
    def __init__(self, shipment_number: int, method: str) -> None:
        self._shipment_number = shipment_number
        self._method = method
        self._status = ShipmentStatus.PENDING


class ShipmentLog:
    def __init__(self, shipment_number: int, status: ShipmentStatus = ShipmentStatus.PENDING) -> None:
        self._shipment_number = shipment_number
        self._status = status
        self._creation_date: date = date.today()


class Shipment:
    def __init__(self, shipment_number: int, shipment_method: str) -> None:
        self._shipment_number = shipment_number
        # when the shipment record was created
        self._shipment_date: date = date.today()
        # estimated arrival date (can be updated by carrier)
        self._estimated_arrival: date = date.today()
        self._shipment_method = shipment_method
        # list of shipment events / logs
        self._shipment_logs: List[ShipmentLog] = []
        self._status = ShipmentStatus.PENDING

    def add_shipment_log(self, shipment_log: 'ShipmentLog') -> None:
        """Append a shipment log/event and optionally update shipment status."""
        self._shipment_logs.append(shipment_log)
        self._status = shipment_log._status


class Transaction:
    def process(self, amount: float, method: str) -> bool:
        return True


class Notification:
    def send_notification(self, account: Account, content: str) -> None:
        pass

Java

import java.util.Date;
import java.util.List;

public enum OrderStatus {
    UNSHIPPED, PENDING, SHIPPED, COMPLETED, CANCELED, REFUND_APPLIED
}

public class Address {
    private String street;
    private String city;
    private String state;
    private String zipCode;
    private String country;
}

public class Account {
    private int id;
    private String userName;
    private String email;

    public void resetPassword() {
        // skeleton
    }
}

public class ShoppingCart {
    private List<Item> items;

    public void addItem(Item item) { }
    public void removeItem(Item item) { }
    public Order checkout() { return null; }
}

public class Item {
    private int productId;
    private int quantity;
    private double price;
}

public class Order {
    private int orderNumber;
    private OrderStatus status;
    private Date orderDate;

    public boolean makePayment(Transaction t) { return true; }
}

public class Shipment { }

public class Transaction { public boolean process(double amount, String method) { return true; } }

public class Notification { public void sendNotification(Account a, String content) { } }

Online Shopping System Sequence Diagram 1

References

Comments