Skip to content

MazenMahmoud21/ecommerce-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

E-commerce Java Application

A Java-based e-commerce desktop application built using Swing GUI framework, demonstrating multiple design patterns and best practices in software engineering.

Table of Contents

Overview

This E-commerce application is a fully functional desktop application that allows customers to:

  • Browse and search products
  • Add items to shopping cart
  • Manage cart with warranty options
  • Complete checkout with multiple payment methods
  • View order history and profile
  • Process orders with different shipping options

The application showcases six major design patterns and follows object-oriented programming principles, making it an excellent learning resource for software engineering students and professionals.

Features

Customer Features

  • User Authentication: Login and registration system with email-based authentication
  • Product Catalog: Browse electronics and clothing products with detailed information
  • Shopping Cart: Add/remove items, apply warranties, view totals
  • Warranty System: Optional warranty coverage for electronics products
  • Checkout Process: Complete order flow with shipping and payment selection
  • Payment Options: Multiple payment methods (Credit Card, PayPal, Cash on Delivery)
  • Shipping Options: Standard and Express shipping with different processing
  • Order History: View past orders and their status
  • Customer Profile: Manage customer information and preferences
  • Real-time Notifications: Observer pattern for order status updates

Technical Features

  • Singleton Pattern: Centralized database connection, cart management, and payment gateway
  • Factory Pattern: Product creation and shipping processor instantiation
  • DAO Pattern: Clean separation of data access logic
  • Strategy Pattern: Flexible payment method implementation
  • Decorator Pattern: Dynamic warranty addition to products
  • Observer Pattern: Order notification system
  • Swing GUI: Professional desktop interface with multiple screens
  • Microsoft SQL Server: Robust relational database backend
  • Maven: Dependency management and build automation

Design Patterns

1. Singleton Pattern

Used for shared system resources that should have only one instance:

  • DBConnection: Manages single database connection
  • CartManager: Global shopping cart accessible throughout the app
  • PaymentGateway: Centralized payment processing

2. Factory Pattern

Creates objects without exposing instantiation logic:

  • ProductFactory: Creates Electronics or Clothing products based on type
  • OrderProcessingFactory: Instantiates StandardProcessor or ExpressProcessor based on shipping selection

3. DAO (Data Access Object) Pattern

Separates persistence logic from business logic:

  • CustomerDAO/CustomerDAOImpl: Customer CRUD operations
  • ProductDAO/ProductDAOImpl: Product data access
  • OrderDAO/OrderDAOImpl: Order and order items persistence

4. Strategy Pattern

Defines family of algorithms (payment methods) that are interchangeable:

  • Multiple payment strategies can be selected at runtime
  • Implemented through PaymentGateway with different strategy interfaces

5. Decorator Pattern

Dynamically adds responsibilities to objects:

  • Warranty: Wraps Product objects to add warranty cost and features
  • Allows flexible pricing without modifying base Product classes

6. Observer Pattern

Defines one-to-many dependency for event notification:

  • OrderSubject: Notifies observers when order status changes
  • Customer: Receives notifications about their orders
  • Observer: Interface for notification recipients

πŸ›  Technologies & Dependencies

Core Technologies

  • Java:
  • Swing: GUI framework for desktop interface
  • Maven: Build automation and dependency management
  • Microsoft SQL Server: Relational database
  • JDBC: Database connectivity

Maven Dependencies

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>12.4.2.jre11</version>
</dependency>

πŸ“ Project Structure

ecommerce-java/
β”œβ”€β”€ README.md
└── ecommerce-app/ecommerce/
    β”œβ”€β”€ pom.xml                    # Maven configuration
    └── src/main/java/com/ecommerce/
        β”œβ”€β”€ dao/                   # Data Access Objects - Database operations
        β”œβ”€β”€ decorator/             # Decorator Pattern - Warranty system
        β”œβ”€β”€ factory/               # Factory Pattern - Product & processor creation
        β”œβ”€β”€ gui/                   # Swing GUI Screens (Main: EcommerceGUI.java)
        β”œβ”€β”€ model/                 # Domain Models - Product, Order, Customer
        β”œβ”€β”€ observer/              # Observer Pattern - Order notifications
        β”œβ”€β”€ processing/            # Order Processing - Standard/Express shipping
        └── singleton/             # Singleton Pattern - Cart, DB, Payment

Prerequisites

Before running this application, ensure you have the following installed:

  1. **Java Development Kit (JDK) **

    java -version
  2. Apache Maven 3.6+

    mvn -version
  3. Microsoft SQL Server

    • SQL Server 2019 or later (Express edition is fine)
    • SQL Server running on localhost:1433 or custom host
    • TCP/IP protocol enabled in SQL Server Configuration Manager
  4. Git (for cloning the repository)

    git clone https://github.com/MazenMahmoud21/ecommerce-java.git

Installation & Setup

Step 1: Clone the Repository

git clone https://github.com/MazenMahmoud21/ecommerce-java.git
cd ecommerce-java

Step 2: Configure Database Connection

  1. Open DBConnection.java

  2. Update the database credentials:

    private static final String URL = "jdbc:sqlserver://127.0.0.1:1433;databaseName=EcommerceDB;encrypt=true;trustServerCertificate=true;";
    private static final String USERNAME = "your_username";  // Update this
    private static final String PASSWORD = "your_password";  // Update this

Step 3: Set Up Database

Step 4: Build the Project

Usage Guide

1. Login/Registration

  • First Time: Click "Register" to create a new account
    • Enter name, email, phone, and address
    • Email must be unique
  • Existing User: Enter your email to login (no password required in demo)

2. Browse Products

  • View all products in a grid layout
  • Products show name, price, description, and type
  • Electronics display warranty months
  • Clothing displays size information

3. Add to Cart

  • Click on a product to view details
  • For Electronics: Choose whether to add warranty coverage
  • Click "Add to Cart" to add item
  • View cart summary showing total items and price

4. Shopping Cart

  • Review all items in your cart
  • See individual prices and totals
  • Warranty items show additional cost
  • Remove items if needed
  • Proceed to checkout

5. Checkout

  • Review order summary
  • Select shipping method:
    • Standard: Lower cost, regular processing
    • Express: Higher cost, priority processing
  • Choose payment method:
    • Credit Card: Simulated card payment
    • PayPal: Simulated PayPal payment
    • Cash on Delivery: Pay when receiving
  • Place order

6. Order Confirmation

  • View order confirmation with order ID
  • See complete order details
  • Payment and shipping information
  • Order status tracking

7. Order History

  • View all your past orders
  • Check order status (Pending, Processing, Shipped, Delivered)
  • See order details and items

8. Profile Management

  • View and update customer information
  • Check account details
  • Update contact information

Database Schema

Entity Relationship Overview

Customers (1) ──< (N) Orders (1) ──< (N) OrderItems >── (N) Products

Tables

Products

  • id: Primary key (auto-increment)
  • name: Product name
  • price: Product price
  • description: Detailed description
  • type: 'Electronics' or 'Clothing'
  • extraParam: Warranty months (Electronics) or Size (Clothing)

Customers

  • id: Primary key (auto-increment)
  • name: Customer full name
  • email: Unique email (login identifier)
  • phone: Contact number
  • address: Delivery address
  • createdDate: Account creation timestamp

Orders

  • id: Primary key (auto-increment)
  • customerId: Foreign key to Customers
  • totalAmount: Total order cost (including shipping)
  • status: Order status (Pending, Processing, Shipped, Delivered)
  • shippingType: 'Standard' or 'Express'
  • shippingCost: Shipping fee
  • paymentMethod: Selected payment method
  • paymentStatus: Payment status
  • orderDate: Order creation timestamp

OrderItems

  • id: Primary key (auto-increment)
  • orderId: Foreign key to Orders
  • productId: Foreign key to Products
  • productName: Snapshot of product name
  • productPrice: Snapshot of product price
  • quantity: Number of items (currently always 1)
  • hasWarranty: Boolean flag for warranty
  • warrantyCost: Warranty cost if applicable
  • subtotal: Line item total

Architecture Details

Application Flow

EcommerceGUI (Entry Point)
    ↓
LoginScreen
    ↓
ProductBrowseScreen β†’ ProductDetailScreen
    ↓                      ↓
    └──────→ CartManager (Singleton) β†β”€β”€β”€β”€β”€β”€β”˜
                ↓
            CartScreen
                ↓
         CheckoutScreen
                ↓
         OrderDAO.saveOrder()
                ↓
      PaymentGateway.processPayment()
                ↓
      OrderProcessingFactory.getProcessor()
                ↓
         OrderSubject.notifyObservers()
                ↓
      OrderConfirmationScreen

Key Design Decisions

  1. Singleton Cart: Cart is global via CartManager to persist across screens
  2. DAO Layer: All database operations isolated in DAO implementations
  3. Factory Creation: Products and processors created via factories for flexibility
  4. Decorator Pricing: Warranty costs calculated via decorator wrapping
  5. Strategy Payment: Payment methods implemented as strategies for easy extension
  6. Observer Notifications: Order updates broadcast to customer observers
  7. EDT Threading: All GUI operations run on Event Dispatch Thread

Database Connection Management

  • Connection created on-demand via DBConnection.getConnection()
  • Singleton ensures single connection instance

πŸ‘¨β€πŸ’» Author

Mazen Mahmoud


License

This project is created for educational purposes to demonstrate design patterns and Java Swing development.

About

A Java-based e-commerce desktop application built using Swing GUI framework, demonstrating multiple design patterns and best practices in software engineering.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages