O'Reilly logo

Agile Principles, Patterns, and Practices in C# by Robert C. Martin, Micah Martin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

29. Factory

image

© Jennifer M. Kohnke

The man who builds a factory builds a temple.

—Calvin Coolidge (1872–1933)

The Dependency-Inversion Principle (DIP) (Chapter 11) tells us that we should prefer dependencies on abstract classes and avoid dependencies on concrete classes, especially when those classes are volatile. Therefore, the following snippet of code violates this principle:

Circle c = new Circle(origin, 1);

Circle is a concrete class. Therefore, those modules that create instances of Circle must violate DIP. Indeed, any line of code that uses the new keyword violates DIP.

There are times when violating DIP is mostly harmless, which is pretty ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required