https://github.com/piamacalanda/softeng2_visitor-pattern-ecommerce
Simple program implements a Visitor Design Pattern to calculate shipping costs for different types of furniture in an e-commerce platform.
https://github.com/piamacalanda/softeng2_visitor-pattern-ecommerce
visitor-design-pattern
Last synced: 9 days ago
JSON representation
Simple program implements a Visitor Design Pattern to calculate shipping costs for different types of furniture in an e-commerce platform.
- Host: GitHub
- URL: https://github.com/piamacalanda/softeng2_visitor-pattern-ecommerce
- Owner: PiaMacalanda
- Created: 2025-03-16T04:59:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-16T10:29:57.000Z (over 1 year ago)
- Last Synced: 2025-10-26T14:42:27.248Z (9 months ago)
- Topics: visitor-design-pattern
- Language: Java
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ecommerce Shipping Calculator (Visitor Pattern)
## Overview
This simple program implements a **Visitor Design Pattern** to calculate shipping costs for different types of furniture in an e-commerce platform. By using this pattern, we ensure flexibility in adding new furniture types without modifying existing classes, promoting **loose coupling** and **extensibility**.
## Problem Scenario
You are a software developer working on an e-commerce platform that sells various types of furniture, including **chairs, tables, and sofas**. The platform requires a **shipping cost calculator** that considers the type and size of the furniture.
Each furniture type has its own **unique shipping cost calculation logic**:
- **Chairs**: Lightweight and have a flat shipping rate.
- **Tables**: Medium-sized and incur a weight-based cost.
- **Sofas**: Bulky and require a distance-based shipping calculation.
Embedding the shipping logic within each furniture class would lead to **tight coupling**, making it difficult to add new furniture types in the future. Instead, we use the **Visitor Pattern** to separate the shipping cost logic from the furniture objects.
## Implementation Details
- The project demonstrates the **Visitor Design Pattern** by defining:
- **Element Interface**: Represents different types of furniture.
- **Concrete Elements**: Implements specific furniture types (Chair, Table, Sofa, etc.).
- **Visitor Interface**: Defines the `visit()` method for handling different furniture types.
- **Concrete Visitor**: Implements the shipping cost calculation logic for each furniture type.
- **Client Code**: Demonstrates how to calculate shipping costs using the visitor pattern.
- **Important Constraints**:
- **Do not use abstract classes**.
- **Use meaningful interface and class names**.
## UML Diagram
