Advertisement
Guest User

example1

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