A Java-based e-commerce desktop application built using Swing GUI framework, demonstrating multiple design patterns and best practices in software engineering.
- Overview
- Features
- Design Patterns
- Technologies & Dependencies
- Project Structure
- Prerequisites
- Installation & Setup
- Running the Application
- Usage Guide
- Database Schema
- Architecture Details
- Author
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.
- 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
- 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
Used for shared system resources that should have only one instance:
DBConnection: Manages single database connectionCartManager: Global shopping cart accessible throughout the appPaymentGateway: Centralized payment processing
Creates objects without exposing instantiation logic:
ProductFactory: Creates Electronics or Clothing products based on typeOrderProcessingFactory: Instantiates StandardProcessor or ExpressProcessor based on shipping selection
Separates persistence logic from business logic:
CustomerDAO/CustomerDAOImpl: Customer CRUD operationsProductDAO/ProductDAOImpl: Product data accessOrderDAO/OrderDAOImpl: Order and order items persistence
Defines family of algorithms (payment methods) that are interchangeable:
- Multiple payment strategies can be selected at runtime
- Implemented through
PaymentGatewaywith different strategy interfaces
Dynamically adds responsibilities to objects:
Warranty: Wraps Product objects to add warranty cost and features- Allows flexible pricing without modifying base Product classes
Defines one-to-many dependency for event notification:
OrderSubject: Notifies observers when order status changesCustomer: Receives notifications about their ordersObserver: Interface for notification recipients
- Java:
- Swing: GUI framework for desktop interface
- Maven: Build automation and dependency management
- Microsoft SQL Server: Relational database
- JDBC: Database connectivity
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>12.4.2.jre11</version>
</dependency>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
Before running this application, ensure you have the following installed:
-
**Java Development Kit (JDK) **
java -version
-
Apache Maven 3.6+
mvn -version
-
Microsoft SQL Server
- SQL Server 2019 or later (Express edition is fine)
- SQL Server running on
localhost:1433or custom host - TCP/IP protocol enabled in SQL Server Configuration Manager
-
Git (for cloning the repository)
git clone https://github.com/MazenMahmoud21/ecommerce-java.git
git clone https://github.com/MazenMahmoud21/ecommerce-java.git
cd ecommerce-java-
Open
DBConnection.java -
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
- 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)
- View all products in a grid layout
- Products show name, price, description, and type
- Electronics display warranty months
- Clothing displays size information
- 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
- Review all items in your cart
- See individual prices and totals
- Warranty items show additional cost
- Remove items if needed
- Proceed to 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
- View order confirmation with order ID
- See complete order details
- Payment and shipping information
- Order status tracking
- View all your past orders
- Check order status (Pending, Processing, Shipped, Delivered)
- See order details and items
- View and update customer information
- Check account details
- Update contact information
Customers (1) ββ< (N) Orders (1) ββ< (N) OrderItems >ββ (N) Products
id: Primary key (auto-increment)name: Product nameprice: Product pricedescription: Detailed descriptiontype: 'Electronics' or 'Clothing'extraParam: Warranty months (Electronics) or Size (Clothing)
id: Primary key (auto-increment)name: Customer full nameemail: Unique email (login identifier)phone: Contact numberaddress: Delivery addresscreatedDate: Account creation timestamp
id: Primary key (auto-increment)customerId: Foreign key to CustomerstotalAmount: Total order cost (including shipping)status: Order status (Pending, Processing, Shipped, Delivered)shippingType: 'Standard' or 'Express'shippingCost: Shipping feepaymentMethod: Selected payment methodpaymentStatus: Payment statusorderDate: Order creation timestamp
id: Primary key (auto-increment)orderId: Foreign key to OrdersproductId: Foreign key to ProductsproductName: Snapshot of product nameproductPrice: Snapshot of product pricequantity: Number of items (currently always 1)hasWarranty: Boolean flag for warrantywarrantyCost: Warranty cost if applicablesubtotal: Line item total
EcommerceGUI (Entry Point)
β
LoginScreen
β
ProductBrowseScreen β ProductDetailScreen
β β
ββββββββ CartManager (Singleton) ββββββββ
β
CartScreen
β
CheckoutScreen
β
OrderDAO.saveOrder()
β
PaymentGateway.processPayment()
β
OrderProcessingFactory.getProcessor()
β
OrderSubject.notifyObservers()
β
OrderConfirmationScreen
- Singleton Cart: Cart is global via
CartManagerto persist across screens - DAO Layer: All database operations isolated in DAO implementations
- Factory Creation: Products and processors created via factories for flexibility
- Decorator Pricing: Warranty costs calculated via decorator wrapping
- Strategy Payment: Payment methods implemented as strategies for easy extension
- Observer Notifications: Order updates broadcast to customer observers
- EDT Threading: All GUI operations run on Event Dispatch Thread
- Connection created on-demand via
DBConnection.getConnection() - Singleton ensures single connection instance
Mazen Mahmoud
- GitHub: @MazenMahmoud21
- Project: ecommerce-java
This project is created for educational purposes to demonstrate design patterns and Java Swing development.