6. Dependency Inversion Principle (DIP) Flashcards
What does the DIP state?
The Dependency Inversion Principle states that high-level modules should not depend on low-level modules—both should depend on abstractions. It also goes on to say that abstractions should not depend on details, but rather details should depend on abstractions.
What are the two kinds of dependencies in C#?
- Compile-time dependencies — references required to compile.
- Run-time dependencies — references required to run.
What kind of dependencies does the DIP mostly have to do with?
Compile-time dependencies.
What direction should your project references point if the DIP is followed?
Away from your low-level infrastructure code and towards high-level business abstractions.
What is “high-level” in the context of the DIP?
Constructs in our code that
- tend to be more abstract,
- relate more to the problem domain and our business rules,
- are generally more process-oriented than detail-oriented,
- and are further away from input/output (eg. forms, buttons, files, databases).
What is “low-level” in the context of the DIP?
Constructs in our code that
- are closer to I/O (where is the input coming from?),
- are commonly referred to as “plumbing code,”
- interact with specific external systems and hardware.
How does seperation of concerns relate to the DIP?
The Dependency Inversion Principle is all about applying separation of concerns — high-level concerns like your domain model or business rules should be kept separate from your low-level concerns like plumbing code.
What are abstractions in C#?
Abstractions in C# refer primarily to interfaces and abstract base classes. Essentially, the types you cannot instantiate.
What construct is generally prefered for abstractions in C# and why?
Interfaces over abstract base classes because interfaces don’t require object inheritance and are a bit more flexible.
What do abstractions define?
A contract — a way of working with the type without actually specifying how that work is going to get done.
What are “details” in the context of the DIP?
Concretions, essentially.
What does the DIP state?
The Dependency Inversion Principle states that high-level modules should not depend on low-level modules—both should depend on abstractions. It also goes on to say that abstractions should not depend on details, but rather details should depend on abstractions.
What does the DIP state?
The Dependency Inversion Principle states that high-level modules should not depend on low-level modules—both should depend on abstractions. It also goes on to say that abstractions should not depend on details, but rather details should depend on abstractions.
What can be said about abstractions vs details in the context of the DIP?
Abstractions shouldn’t be coupled to details, meaning that they shouldn’t know about the specifics of how they are implemented.
What is the difference between abstractions and details?
Abstractions describe the “what” (eg. send a message, store a Customer record), whereas details specify the “how” (eg. send an SMTP email over port 25, serialize Customer to JSON and store it in a text file).