Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun main() {
- val fan = Fan()
- val conditioner = Conditioner()
- val heater = Heater()
- val climatControl = ClimatControl()
- climatControl.coolToOn(fan)
- climatControl.coolToOn(conditioner)
- climatControl.heatToOn(heater)
- }
- class ClimatControl { // климат контроль
- fun coolToOn(element: Cooling) {
- element.cool()
- }
- fun heatToOn(element: Heating) {
- element.heat()
- }
- }
- interface Cooling {
- fun cool() //охлаждение
- }
- interface Heating {
- fun heat() //обогрев
- }
- class Fan : Cooling {
- override fun cool() {
- println("Fan is on!")
- }
- }
- class Conditioner : Cooling {
- override fun cool() {
- println("Conditioner is on!")
- }
- }
- class Heater : Heating {
- override fun heat() {
- println("Heater is on!")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment