Object-Oriented Programming: Beyond the Basics

Oct 17 2023 · Swift 5.9, iOS 17, Xcode 15

Lesson 05: Liskov Substitution, Interface Segregation & Dependency Inversion

Demo 2

Episode complete

Play next episode

Next

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

In the last demo, you learned about the Liskov Substitution principle. In this demo, you’ll put the Interface Segregation principle to work.

protocol CarControlsProtocol {
  func accelerate()
  func brake()
  func steer()
}

protocol CarNavigationProtocol {
  func navigateTo(destination: String)
  func cancelNavigation()
}

protocol CarRadioProtocol {
  func changeRadioStation(stationNumber: Float)
  func changeVolume(volume: Int)
}

protocol CarACProtocol {
  func getCarTemperature() -> Int
  func setTemperature(temp: Int)
  func setFanSpeed(speed: Int)
}
class AICarControlsModule {
  var carReference: CarControlsProtocol! // updated
}

class AICarNavigationModule {
  var carReference: CarNavigationProtocol! // updated
}

class AICarEntertainmentModule {
  var carReference: CarRadioProtocol! // updated
}

class AICarWeatherModule {
  var carReference: CarACProtocol! // updated
}
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction 2 Next: Instruction 3