A well-designed smart home system requires a balance between specialized behavior and universal standards. This project implements a Smart Device Framework using an abstract Device class. It demonstrates how to combine abstract methods (for device-specific "turn on" procedures) with concrete methods (for a standardized "turn off" algorithm). By inheriting from this base, the Phone class provides its own unique startup sequence while automatically gaining the standard shutdown functionality provided by the parent class.
- Hybrid Abstraction: Created an abstract class
Devicewith both abstract and concrete behaviors. - Specific Implementation: Defined a unique
turnOn()logic within thePhonesubclass. - Inherited Functionality: Leveraged the base
turnOff()implementation to avoid code duplication. - Sequential Testing: Verified the device lifecycle (activation followed by deactivation) in the launcher.
- Java 8+ (Abstract Classes, Inheritance, Method Implementation)
- Device: The abstract base combining a mandatory startup contract with a universal shutdown method.
- Phone: A concrete smart device implementing its own startup sequence.
- SmartHomeLauncherApp: The entry point for simulating device interaction.
Phone on.
Device off.
Project Structure:
JavaBasics_Task_329/
├── src/
│ └── com/yurii/pavlenko/
│ ├── app/
│ │ └── SmartHomeLauncherApp.java
│ └── device/
│ ├── gadgets/
│ │ └── Phone.java
│ └── Device.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md
Code
package com.yurii.pavlenko.app;
import com.yurii.pavlenko.device.gadgets.Phone;
public class SmartHomeLauncherApp {
public static void main(String[] args) {
Phone phone = new Phone();
phone.turnOn();
phone.turnOff();
}
}package com.yurii.pavlenko.device;
public abstract class Device {
public abstract void turnOn();
public void turnOff() {
System.out.println("Device off.");
}
}package com.yurii.pavlenko.device.gadgets;
import com.yurii.pavlenko.device.Device;
public class Phone extends Device {
@Override
public void turnOn() {
System.out.println("Phone on.");
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT