The Dependency Inversion Principle

The concept of avoiding concreate classes isn't new. Robert C. Martin defined this idea in The C++ Report in May 1996 in an article titled The Dependency Inversion Principle. It is the D in his SOLID design principles. The principle has two parts:

  • High-level modules should not depend on low-level modules. Both should depend on abstractions.
  • Abstractions should not depend on details. Details should depend on abstractions.

While this may seem like a mouthful, the concept is actually very easy. Imagine we have a StageManager class that is responsible for initializing, updating, and shutting down all of the stages in our game. In this case, our StageManager is our high-level modules, and the stages are the ...

Get Game Development Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.