-
Notifications
You must be signed in to change notification settings - Fork 6
Home
In Agile development you may have heard of SOLID principles, where the S stands for Single Responsibility. That's a very important point. With constructor injection and the help of a IoC we are already doing a great improvement:
- We remove responsibility of creating a class from another class. => allow for really having classes with a single responsibility
Using a container is about having a class hiearchy wich is used in whole or in part almost statically, for most applications that is already enough, however using the container to create objects at runtime is considered an antipattern (it is like allowing to use any service, wich is a Service Locator, another antipattern), the most elegant way to solve that is using a Factory for creating instances. Note that you don't have to use a "Container provided factory", the responsibility for a Factory is creating objects so it is ok if objects are really created by the factory and not by the framework.
Having a working program, means also having dependencies. You can reduce them, but you cannot remove dependencies, however, if you are dependent on 5 classes, but you are using only few methods on each class, it is possible that you can create 2/3 wrapper classes (Facade Pattern) that hides most unused functionalities and provide maybe a more convenient API for accessing the functionality.