From the course: iOS Development: Architecture
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Dependency inversion
- The Dependency Inversion Principle is one of the main pillars of reusability in object-oriented systems. Let's start with the definition, which consists of two parts. High-level modules should not depend on lower-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions. Now, these rules may sound complicated at first but they boil down to removing the dependencies. Let me illustrate the concept through an example. You've got the Persistence class. You can see it at line four. It can save objects of data to a given location pointed to by a url. The Persistence class uses an instance of the logger class to produce log messages. The Logger class is defined at line 17. In this scenario, Persistence is a high-level class and Logger is a lower-level class. There's a tight coupling between the Persistence and the Logger classes. If the Logger class' interface changes, we need to modify the Persistence class as well.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.