Untitled

mail@pastecode.io avatar
unknown
java
2 months ago
857 B
0
Indexable
Never
// Prototype interface representing IoT devices
interface IoTDevice extends Cloneable {
IoTDevice clone () ;
void configure () ;
}
// Concrete implementation of the Prototype pattern for a Smart Light
class SmartLight implements IoTDevice {
@Override
public IoTDevice clone () {
return new SmartLight () ;
}

@Override
public void configure () {
System . out . println ( " Configuring Smart Light ... " ) ;
// Additional configuration logic
}
}

// Client class for smart home simulation
public class SmartHomeSimulation {
public static void main ( String [] args ) {
IoTDevice smartLightPrototype = new SmartLight () ;

// Create and configure smart lights dynamically
IoTDevice light1 = smartLightPrototype . clone () ;
light1 . configure () ;

IoTDevice light2 = smartLightPrototype . clone () ;
light2 . configure () ;
}
}
Leave a Comment