This project demonstrates the integration of six critical design patterns into a console-based inventory management application developed in Java, featuring a modern Single Page Application (SPA) simulation for the frontend.
- Backend: Developed in Java, incorporating Composite, Decorator, Observer, Strategy, Singleton, and Builder patterns.
- Frontend (SPA): Built using HTML, CSS, and JavaScript. The UI simulates a modern SPA by using the
fetchAPI to load content dynamically into the main area (#content-container) upon menu selection. - Scope Resolution: All interaction functions (
simulateAddCategory,simulateStrategy, etc.) are defined in the global scope (index.html) to prevent JavaScriptReferenceErrorissues caused by dynamic page loading.
| Pattern | Category | Role in Application |
|---|---|---|
| Composite | Structural | Manages the hierarchy between Categories and Products. |
| Decorator | Structural | Dynamically adds price adjustments (e.g., discount/markup) to products. |
| Observer | Behavioral | Monitors stock levels and triggers alerts upon changes (Low Stock). |
| Strategy | Behavioral | Enables dynamic switching of pricing logic (Normal vs. Tax Included). |
| Singleton | Creational | Manages global application settings (ConfigurationManager) centrally. |
| Builder | Creational | Provides controlled, step-by-step creation for complex products (e.g., Laptops). |
The application requires running the Java Backend and the Web Frontend processes concurrently.
This process runs the core application logic and outputs all logs and alerts.
- In your command line, navigate to the
backenddirectory. - Compile all Java source files:
javac *.java - Start the main application (Core Logic):
(Keep this console window open; all logs, alerts, and pattern outputs will appear here.)
java Main
The web frontend must be served over HTTP to allow JavaScript fetch API calls to work correctly (bypassing local file security restrictions).
- Open a new command line window and navigate to the
backenddirectory (whereSimpleHttpServer.javais located). - Start the Frontend Server:
java SimpleHttpServer
- Open your browser and navigate to the application address:
http://localhost:8000/index.html
You can now interact with the web interface, and the resulting actions will simulate signals being sent to your running Java console.