Advertisement
Guest User

example1

a guest
May 27th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.76 KB | None | 0 0
  1. final class Car {
  2.     enum Direction: CustomStringConvertible {
  3.         case straight
  4.         case right
  5.         var description: String {
  6.             switch self {
  7.             case .right:
  8.                 return "right"
  9.             case .straight:
  10.                 return "straight"
  11.             }
  12.         }
  13.     }
  14.     func go(direction: Direction) {
  15.         print(direction.description)
  16.     }
  17. }
  18.  
  19. protocol Drivable: class {
  20.     func drive()
  21. }
  22.  
  23. final class A: Drivable {
  24.     private let car = Car.init()
  25.     func drive() {
  26.         car.go(direction: .straight)
  27.     }
  28. }
  29. final class B: Drivable {
  30.     private let car = Car.init()
  31.     func drive() {
  32.         car.go(direction: .right)
  33.     }
  34. }
  35. let ad = A.init()
  36. ad.drive()
  37. let bd = B.init()
  38. bd.drive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement