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’re accessing parts of this content for free, with some sections shown as ivryctirek text.

Heads up... You’re accessing parts of this content for free, with some sections shown as abxuwratuk text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

00:01In 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