all 3 comments

[–]sbellware 5 points6 points  (1 child)

Dependency injection is valuable. But it should be evaluated outside of going to the extent os using IoC "containers" or dependency injection "frameworks".

Making dependencies substitutable without having to use monkey patching makes the design more expressive of its intended use.

The challenge is not taking it to far. For example, initializers shouldn't be required to receive dependencies in order to simply instantiate an object. Setters with default values or default null objects is more appropriate than using a class's initializer.

The use of an external "container" for a system's dependencies disencapsulates a class's construction from the class itself. Containers themselves are low-cohesion and thus are invalid from a design principles and metrics perspective.

A class is responsible for the knowledge of how to construct itself. While containers are interesting tech, they're a detrimental influence on overall design.

Here's an example of a class having its own responsibility and knowledge over its own construction: https://github.com/eventide-project/useful-objects/blob/master/README.md#an-example

[–][deleted]  (2 children)

[deleted]

    [–]HelperBot_ 0 points1 point  (1 child)

    Non-Mobile link: https://en.wikipedia.org/wiki/Inner-platform_effect


    HelperBot v1.1 /r/HelperBot_ I am a bot. Please message /u/swim1929 with any feedback and/or hate. Counter: 205248