gazievDima

Untitled

May 18th, 2021
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. fun main() {
  2.  
  3. val fan = Fan()
  4. val conditioner = Conditioner()
  5. val heater = Heater()
  6.  
  7. val climatControl = ClimatControl()
  8. climatControl.coolToOn(fan)
  9. climatControl.coolToOn(conditioner)
  10. climatControl.heatToOn(heater)
  11. }
  12.  
  13. class ClimatControl { // климат контроль
  14. fun coolToOn(element: Cooling) {
  15. element.cool()
  16. }
  17. fun heatToOn(element: Heating) {
  18. element.heat()
  19. }
  20. }
  21.  
  22. interface Cooling {
  23. fun cool() //охлаждение
  24. }
  25.  
  26. interface Heating {
  27. fun heat() //обогрев
  28. }
  29.  
  30. class Fan : Cooling {
  31. override fun cool() {
  32. println("Fan is on!")
  33. }
  34. }
  35.  
  36. class Conditioner : Cooling {
  37. override fun cool() {
  38. println("Conditioner is on!")
  39. }
  40. }
  41.  
  42. class Heater : Heating {
  43. override fun heat() {
  44. println("Heater is on!")
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment