29 lines
563 B
Kotlin
29 lines
563 B
Kotlin
package drills.drill06.exercise4.actuator
|
|
|
|
interface Action {
|
|
enum class State {
|
|
ON, OFF
|
|
}
|
|
|
|
fun getActionName(): String
|
|
fun getState(): State
|
|
fun on()
|
|
fun off()
|
|
}
|
|
|
|
abstract class VirtualAction : Action {
|
|
private var state = Action.State.OFF
|
|
|
|
override fun getState(): Action.State = state
|
|
|
|
override fun off() {
|
|
println("Switching off: ${getActionName()}")
|
|
state = Action.State.OFF
|
|
}
|
|
|
|
override fun on() {
|
|
println("Switching on: ${getActionName()}")
|
|
state = Action.State.ON
|
|
}
|
|
}
|