Day 10 - Systems
Separate constructing system from using it
- Software systems should separate the startup process, when the application objects are constructed and the dependencies are “wired” together; from the runtime logic that takes over after startup
Separation of main
-
One way to separate construction from use is simply to move all aspects of construction to modules called by main, and to design the rest of the system assuming that all objects have been constructed and wired up appropriately
public class Main { public static void main(String[] args) { build(); run(); } }
Dependency injection
- Dependency injection is the application of Inversion of Control, to dependency management
- Inversion of control moves secondary responsibilities from an object to other objects that are dedicated to the purpose, thereby supporting the single responsibility principle