How em3rc0d/designpatternsdsi works
Project Type and Purpose
• This is a standalone Java Swing desktop application (“Tienda Online de Electrónicos”) designed to demonstrate and teach advanced object-oriented design patterns in the context of a simple online store.
• It’s not a distributed microservice system but a modular single-process app structured into logical layers and pattern-specific packages.
File Structure
• Top-level build files: pom.xml, Maven wrapper.
• src/main/java/design_patterns is split into subpackages by pattern:
• gui – GUI entry point (OnlineStoreApp, StoreGUI)
• model – Product entities (Laptop, Smartphone, etc.)
• factory & brandFactory – Factory Method and Abstract Factory
• builder – ProductBuilder
• decorator – WarrantyDecorator, ProductDecorator
• adapter – PaymentAdapter, ExternalPaymentService, Payment interface
• singleton – CartManager
• No external database or web server; state is held in memory.
README for Additional Insights
• Lists all patterns: Singleton, Factory Method, Abstract Factory, Builder, Adapter, Decorator.
• GUI driven by Java Swing.
• Simulated external payment via an Adapter wrapping an ExternalPaymentService.
Components
a. GUI Layer
• Component: StoreGUI (Swing frames, panels, event handlers)
• Component: OnlineStoreApp (main)
b. Domain / Business Logic Layer
• Model: Product, Laptop, Smartphone, Tablet, Smartwatch
• Singleton: CartManager (holds selected products and total)
• Factory Packages
• ProductFactory (Factory Method)
• BrandFactory (Abstract Factory)
• Builder: ProductBuilder (construct complex product instances)
• Decorator: ProductDecorator, WarrantyDecorator (dynamically extend products)
c. Integration / External Services
• Adapter: PaymentAdapter implements Payment → wraps ExternalPaymentService
• ExternalPaymentService: simulates remote payment gateway
Relationships and Interactions
• StoreGUI instantiates products via factories or builder, then calls CartManager.getInstance().add(product)
• CartManager notifies GUI to refresh total (pull by GUI or event callback).
• On “Process Payment”: GUI calls PaymentAdapter.pay(amount), which delegates to ExternalPaymentService.process(amount).
• Decorator can be applied before adding to cart (e.g., new WarrantyDecorator(baseProduct)).
Architectural Patterns & Principles
• Layering:
• Presentation (GUI)
• Domain / Business Logic (models, CartManager, factories, builders, decorators)
• Integration / Infrastructure (adapter, external service)
• Design Patterns: each package is a self-contained implementation of its pattern.
• Single Responsibility: GUI only handles UI; CartManager only handles cart state.
Technologies, Frameworks, Libraries
• Java SE
• Java Swing (GUI)
• Maven (build)
• No database / persistence layer
Essential Elements
• Component Labels: StoreGUI, OnlineStoreApp, CartManager, ProductFactory, BrandFactory, ProductBuilder, WarrantyDecorator, PaymentAdapter, ExternalPaymentService
• GUI → Factories / Builder (product creation)
• GUI → CartManager (add/remove/empty)
• GUI → PaymentAdapter (process payment)
• PaymentAdapter → ExternalPaymentService (delegate payment)
• Annotations: Pattern names next to each component (e.g., «Singleton» CartManager)