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 3

Episode complete

Play next episode

Next

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

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

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

Unlock now

In this demo, you’ll put the Dependency Inversion principle to work by applying it to the system you refactored in the first demo. I’ve moved the system initialzation underneath all the class initializations.

protocol LoggingProtocol {
  func addLogEntry(_ entry: String)
}
class LogManager: LoggingProtocol {
 ...
class System {
  var activeView = SimulatedView()
  var logger: LoggingProtocol // new code

  init(logger: LoggingProtocol) { // new code
     self.logger = logger
  }
...
logger.addLogEntry(logEntry)
let system = System(logger: LogManager.singleton())
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction 3 Next: Conclusion