The Dependency Inversion Principle

What is a Dependency Inversion Principle? The Dependency Inversion Principle means that high-level modules should not depend on low-level modules. Source Source What problems does it solve? The Dependency Inversion Principle (DIP) helps solve: Rigidity Fragility Immobility problems Real-world code example Violation of DIP // High-level module directly depending on low-level modules class MessageService { func sendMessageViaEmail(message: String) { let emailSender = EmailSender() emailSender.sendMessage(message: message) } func sendMessageViaSMS(message: String) { let smsSender = SMSSender() smsSender....

March 5, 2024 · 2 min · Dmytro Chumakov