Skip to content

onurcangnc/SmartHomeSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏠 Smart Home Automation System

Java License Design Patterns Bilkent University

A comprehensive Smart Home Automation System demonstrating the practical application of six fundamental software design patterns. Built as part of CTIS 417 - Software Design Patterns course at Bilkent University.

πŸ‘₯ Team Members

Name Role
Onurcan GenΓ§ Developer
Efe Baran Durmaz Developer
Moein Faghih Developer

πŸ“‹ Table of Contents

✨ Features

Feature Description Pattern Used
🌐 Multi-Protocol Support WiFi 2.4GHz, WiFi 5GHz, IEEE 802.15.4 Abstract Factory
πŸ“‘ Real-time Monitoring Instant notifications to multiple clients Observer
πŸ” Role-Based Access Admin and User permission levels Proxy
🏒 Hierarchical Management Building β†’ Room β†’ Device structure Composite
πŸŽ›οΈ Centralized Control All devices coordinated through hub Mediator
βš™οΈ Global Configuration Single source of system settings Singleton

🎨 Design Patterns

Overview

# Pattern Type Class Purpose
1 Singleton Creational SystemConfiguration Single instance for global system settings
2 Abstract Factory Creational DeviceFactory Protocol-specific device creation
3 Composite Structural BuildingComposite Hierarchical building/room/device structure
4 Proxy Structural SecureDeviceProxy Role-based access control
5 Observer Behavioral Subject/Observer Event notification system
6 Mediator Behavioral SmartHomeHubMediator Centralized device coordination

Pattern Distribution

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    DESIGN PATTERNS                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   CREATIONAL    β”‚   STRUCTURAL    β”‚      BEHAVIORAL         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Singleton     β”‚ β€’ Composite     β”‚ β€’ Observer              β”‚
β”‚ β€’ Abstract      β”‚ β€’ Proxy         β”‚ β€’ Mediator              β”‚
β”‚   Factory       β”‚                 β”‚                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š UML Class Diagram

The complete system architecture showing all classes, interfaces, and their relationships:

UML Class Diagram

πŸ“– Click to view diagram explanation

Key Components:

  • CompositeComponent (Interface): Base interface for all controllable elements
  • Device (Interface): Extends CompositeComponent, adds reset functionality
  • Subject/Observer (Interfaces): Enables publish-subscribe pattern
  • DeviceFactory (Interface): Abstract factory for creating device families
  • SmartHomeHubMediator: Central coordinator for all device interactions
  • SecureDeviceProxy: Protection proxy for access control

Relationships:

  • Inheritance: Device classes implement Device interface
  • Composition: BuildingComposite contains CompositeComponents
  • Association: Mediator manages Device collection
  • Dependency: Factories create Device instances

πŸ— System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           Main                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό                      β–Ό                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SystemConfig  β”‚    β”‚  DeviceFactory  β”‚    β”‚ SecureDevice   β”‚
β”‚  (Singleton)  β”‚    β”‚ (Abstract Fact.)β”‚    β”‚    Proxy       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚                      β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
              β–Ό               β–Ό               β–Ό      β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
        β”‚WiFi 2.4  β”‚   β”‚WiFi 5GHz β”‚   β”‚LowPower  β”‚  β”‚
        β”‚ Factory  β”‚   β”‚ Factory  β”‚   β”‚ 802.15.4 β”‚  β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
              β”‚               β”‚               β”‚      β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
                              β–Ό                      β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SmartHomeHubMediator                         β”‚
β”‚                      (Central Hub)                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό         β–Ό           β–Ό           β–Ό         β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Light  β”‚ β”‚Thermo- β”‚ β”‚ Motion   β”‚ β”‚ Door   β”‚ β”‚Buildingβ”‚
   β”‚        β”‚ β”‚ stat   β”‚ β”‚ Sensor   β”‚ β”‚ Lock   β”‚ β”‚Compsiteβ”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚             β”‚
                  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                         β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚        Observers            β”‚
          β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
          β”‚ β€’ DashboardView             β”‚
          β”‚ β€’ MobileAppClient           β”‚
          β”‚ β€’ AlertService              β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

CTIS417_Java/
β”‚
β”œβ”€β”€ πŸ“„ CTIS417_Java.iml          # IntelliJ IDEA module file
β”œβ”€β”€ πŸ“„ .gitignore                 # Git ignore rules
β”œβ”€β”€ πŸ“„ README.md                  # This file
β”œβ”€β”€ πŸ“„ LICENSE                    # MIT License
β”‚
β”œβ”€β”€ πŸ“‚ src/
β”‚   β”œβ”€β”€ πŸ“‚ app/
β”‚   β”‚   └── πŸ“„ Main.java                    # πŸš€ Entry point
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ“‚ config/
β”‚   β”‚   └── πŸ“„ SystemConfiguration.java     # βš™οΈ Singleton
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ“‚ device/
β”‚   β”‚   β”œβ”€β”€ πŸ“„ Device.java                  # Interface
β”‚   β”‚   β”œβ”€β”€ πŸ“„ Light.java                   # πŸ’‘ Light device
β”‚   β”‚   β”œβ”€β”€ πŸ“„ Thermostat.java              # 🌑️ Temperature control
β”‚   β”‚   β”œβ”€β”€ πŸ“„ MotionSensor.java            # πŸ‘οΈ Motion detection
β”‚   β”‚   └── πŸ“„ DoorLock.java                # πŸ”’ Security lock
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ“‚ factory/
β”‚   β”‚   β”œβ”€β”€ πŸ“„ DeviceFactory.java           # 🏭 Abstract Factory
β”‚   β”‚   β”œβ”€β”€ πŸ“„ WiFi24GHzDeviceFactory.java  # 2.4GHz implementation
β”‚   β”‚   β”œβ”€β”€ πŸ“„ WiFi5GHzDeviceFactory.java   # 5GHz implementation
β”‚   β”‚   └── πŸ“„ LowPower80215DeviceFactory.java # 802.15.4 implementation
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ“‚ composite/
β”‚   β”‚   β”œβ”€β”€ πŸ“„ CompositeComponent.java      # 🧩 Component interface
β”‚   β”‚   └── πŸ“„ BuildingComposite.java       # 🏒 Composite container
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ“‚ observer/
β”‚   β”‚   β”œβ”€β”€ πŸ“„ Observer.java                # πŸ‘€ Observer interface
β”‚   β”‚   β”œβ”€β”€ πŸ“„ Subject.java                 # πŸ“’ Subject interface
β”‚   β”‚   β”œβ”€β”€ πŸ“„ DashboardView.java           # πŸ“Š Dashboard client
β”‚   β”‚   β”œβ”€β”€ πŸ“„ MobileAppClient.java         # πŸ“± Mobile client
β”‚   β”‚   └── πŸ“„ AlertService.java            # 🚨 Alert service
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ“‚ mediator/
β”‚   β”‚   └── πŸ“„ SmartHomeHubMediator.java    # πŸŽ›οΈ Central mediator
β”‚   β”‚
β”‚   └── πŸ“‚ proxy/
β”‚       └── πŸ“„ SecureDeviceProxy.java       # πŸ›‘οΈ Security proxy
β”‚
β”œβ”€β”€ πŸ“‚ docs/
β”‚   β”œβ”€β”€ πŸ“„ Class_Diagram.svg                # πŸ“Š UML Class Diagram
β”‚   └── πŸ“„ SmartHome_DesignPatterns_CTIS417.pptx  # πŸ“½οΈ Presentation
β”‚
└── πŸ“‚ out/                                  # Compiled classes (ignored)

πŸš€ Installation

Prerequisites

  • β˜• Java JDK 17 or higher
  • πŸ’» IntelliJ IDEA (recommended) or any Java IDE
  • πŸ”§ Git

Option 1: Clone with Git

# Clone the repository
git clone https://github.com/yourusername/SmartHomeAutomation.git

# Navigate to project directory
cd SmartHomeAutomation

Option 2: Open in IntelliJ IDEA

  1. Open IntelliJ IDEA
  2. File β†’ Open β†’ Select project folder
  3. Trust the project
  4. Wait for indexing to complete
  5. Run Main.java

Option 3: Command Line

# Compile all Java files
javac -d out src/**/*.java

# Run the application
java -cp out app.Main

πŸ’» Usage

Basic Example

// 1. Get system configuration (Singleton)
SystemConfiguration config = SystemConfiguration.getInstance();
config.printCurrentConfiguration();

// 2. Create devices using Abstract Factory
DeviceFactory wifiFactory = new WiFi24GHzDeviceFactory();
Light light = wifiFactory.createLight();
Thermostat thermostat = wifiFactory.createThermostat();

// 3. Set up Observer pattern for notifications
DashboardView dashboard = new DashboardView();
AlertService alerts = new AlertService();
thermostat.addObserver(dashboard);
thermostat.addObserver(alerts);

// 4. Use Composite pattern for building structure
BuildingComposite building = new BuildingComposite();
BuildingComposite livingRoom = new BuildingComposite();
livingRoom.add(light);
livingRoom.add(thermostat);
building.add(livingRoom);

// Turn on all devices in building
building.turnOn();

// 5. Use Mediator for centralized control
SmartHomeHubMediator hub = new SmartHomeHubMediator();
hub.addDevice(light);
hub.addDevice(thermostat);
hub.resetSensors();

// 6. Use Proxy for access control
CompositeComponent secureLight = new SecureDeviceProxy(light, hub, "admin");
secureLight.turnOn();  // βœ… Access granted

CompositeComponent userLight = new SecureDeviceProxy(light, hub, "user");
userLight.turnOn();    // ❌ Access denied

βš™οΈ Configuration

The SystemConfiguration singleton provides centralized configuration management:

Network Settings

Setting Default Description
hubIpAddress 192.168.1.100 Smart Hub IP
hubPort 8080 Hub port number
wifiSSID SmartHome_Network WiFi network name
maxConnectedDevices 50 Maximum devices
networkTimeout 30000ms Connection timeout

Security Settings

Setting Default Description
securityEnabled true Enable security
maxLoginAttempts 3 Login attempt limit
sessionTimeoutMinutes 30 Session duration
twoFactorEnabled false 2FA status
encryptionAlgorithm AES-256 Encryption type

Temperature Thresholds

Setting Default Description
minTemperatureThreshold 16.0Β°C Minimum comfortable
maxTemperatureThreshold 28.0Β°C Maximum comfortable
criticalHighTemperature 40.0Β°C Fire alarm trigger
criticalLowTemperature 5.0Β°C Freeze warning

Energy Management

Setting Default Description
energySavingMode false Energy saving
maxPowerConsumptionWatts 5000W Power limit
peakHoursStart 17:00 Peak hours begin
peakHoursEnd 21:00 Peak hours end

πŸ“Ί Demo Output

╔════════════════════════════════════════════════════════════╗
β•‘         SMART HOME SYSTEM CONFIGURATION LOADED             β•‘
╠════════════════════════════════════════════════════════════╣
β•‘  System: SmartHome Hub Pro                                 β•‘
β•‘  Version: 2.1.0                                            β•‘
β•‘  Hub IP: 192.168.1.100:8080                                β•‘
β•‘  Security: ENABLED                                         β•‘
β•‘  Max Devices: 50                                           β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

=== Singleton Pattern ===
SystemConfiguration instance created.
Same instance: true

=== Abstract Factory Pattern ===
WiFi24GHzDeviceFactory: Creating Light.
WiFi24GHzDeviceFactory: Creating Thermostat.
LowPower80215DeviceFactory: Creating MotionSensor.
LowPower80215DeviceFactory: Creating DoorLock.

=== Observer Pattern ===
-- MotionSensor detects motion --
MotionSensor: Motion detected!
DashboardView: Received update notification. Motion detected!
AlertService: Received update notification. Motion detected!

-- Thermostat detects abnormal temperature --
⚠️  Thermostat: HIGH temperature detected! 45.0°C exceeds max threshold
DashboardView: Received update notification. Temperature Alert!
MobileAppClient: Received update notification. Temperature Alert!

=== Mediator Pattern ===
MotionSensor reset. No motion detected as default.
Thermostat reset. Temperature read as 25Β°C by default.
DoorLock reset. Unlocked by default.
Light reset. Off by default.

=== Composite Pattern ===
BuildingComposite: Turning on all children.
  Light turned on.
  Thermostat turned on.
  MotionSensor turned on.
  DoorLock locked.

=== Proxy Pattern ===
-- ADMIN user accessing Light --
Mediator: Checking access for role 'admin' to perform 'turnOn'
Mediator: Access GRANTED.
Light turned on.

-- USER accessing Light --
Mediator: Checking access for role 'user' to perform 'turnOn'
Mediator: Access DENIED.

exp run 1

exp run 2

exp run 3

exp run 4

πŸ“š Documentation

Document Description Link
πŸ“Š UML Class Diagram Complete system architecture Class_Diagram.svg
πŸ“½οΈ Presentation Project presentation slides PPTX
πŸ“– This README Project documentation You're here!

πŸ› οΈ Technologies Used

  • Language: Java 17+
  • IDE: IntelliJ IDEA
  • Build: Standard Java Compiler
  • Version Control: Git & GitHub
  • Documentation: Markdown, Mermaid (UML)

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2024 Onurcan GenΓ§, Efe Baran Durmaz, Moein Faghih

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software...

πŸ™ Acknowledgments

  • πŸ“š CTIS 417 - Software Design Patterns Course
  • πŸŽ“ Bilkent University - Department of Computer Technology and Information Systems
  • πŸ“– Gang of Four - Design Patterns: Elements of Reusable Object-Oriented Software
  • πŸ‘¨β€πŸ« Our instructor for guidance and feedback

Made with Java Design Patterns Built at Bilkent

Made with ❀️ by Onurcan, Efe Baran & Moein

⭐ Star this repository if you found it helpful!

About

Smart Home Automation System implementing 6 Gang of Four design patterns over 23 (Singleton, Abstract Factory, Observer, Mediator, Composite, Proxy) in Java. CTIS 417 - Bilkent University

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages