A Spring Boot MVC web application demonstrating the Command Design Pattern for Smart Home IoT device control.
This project implements a web dashboard that controls a smart light bulb using the Command Design Pattern. The architecture cleanly separates concerns:
- Invoker (SmartHomeController): Receives HTTP requests and creates/executes commands
- Command Interface: Defines the
execute()contract for all commands - Concrete Commands:
LightOnCommandandLightOffCommandencapsulate specific actions - Receiver (LightService): Contains the actual hardware control logic
┌─────────────────┐ ┌───────────────────┐ ┌─────────────────┐
│ User │───▶│ SmartHomeController│───▶│ Command │
│ (Web Dashboard)│ │ (Invoker) │ │ (Interface) │
└─────────────────┘ └───────────────────┘ └────────┬────────┘
│
┌───────────────────────────┴───────────────────────────┐
│ │ │
┌──────▼──────┐ ┌─────▼───────┐ │
│LightOnCommand│ │LightOffCommand│ │
│ (Concrete) │ │ (Concrete) │ │
└──────┬───────┘ └──────┬────────┘ │
│ │ │
└─────────────┬───────────────┘ │
│ │
┌──────▼──────┐ │
│ LightService │◀──────────────────────────────────────┘
│ (Receiver) │
└──────────────┘
- Java 17 or higher
- Maven 3.6+
mvn clean installmvn spring-boot:run# Turn ON the light
curl http://localhost:8080/light/on
# Turn OFF the light
curl http://localhost:8080/light/off
# Check light status
curl http://localhost:8080/light/statussrc/main/java/com/smarthome/
├── SmartHomeApplication.java # Main application entry point
├── command/
│ ├── Command.java # Command interface
│ ├── LightOnCommand.java # Concrete command to turn ON
│ └── LightOffCommand.java # Concrete command to turn OFF
├── controller/
│ └── SmartHomeController.java # REST controller (Invoker)
└── service/
└── LightService.java # Light service (Receiver)
docs/
└── COMMAND_PATTERN.md # Detailed documentation with UML diagrams
For detailed documentation including:
- Conceptual Mapping
- PlantUML Class Diagram
- PlantUML Sequence Diagram
- Implementation Details
mvn test- Decoupling: The Controller doesn't know HOW to control the light—only the Command and Service know that
- Single Responsibility: Each class has one job
- Open/Closed Principle: New commands can be added without modifying existing code
- Testability: Each component can be tested independently
- Extensibility: Easy to add features like undo/redo, command history, or command queuing
This project is for educational purposes as part of a university assignment.