iluwatar / java-design-patterns

Design patterns implemented in Java
https://java-design-patterns.com
Other
90k stars 26.61k forks source link

Composition root pattern #379

Open npathai opened 8 years ago

npathai commented 8 years ago

Description:

The Composition Root design pattern is a method of organizing code to ensure that all dependencies are created in a single location within an application. This helps manage dependencies more effectively, improve testability, and promote a clear separation of concerns. By centralizing the creation of dependencies, the Composition Root pattern ensures that an application's object graph is constructed in a consistent manner.

Main elements of the pattern:

  1. Centralized Dependency Creation: All dependencies are instantiated in a single location, typically at the application's entry point.
  2. Dependency Injection: Dependencies are injected into classes rather than being created within those classes, supporting Inversion of Control (IoC).
  3. Separation of Concerns: Ensures that the construction of objects and their usage are separate, enhancing maintainability and testability.

References:

Acceptance Criteria:

  1. Implement the Composition Root pattern in the project, ensuring all dependencies are instantiated in a single location at the application's entry point.
  2. Demonstrate the use of dependency injection to provide these dependencies to various components of the application.
  3. Ensure that the implemented pattern adheres to the project’s contribution guidelines and includes relevant documentation and examples.
npathai commented 8 years ago

Reference: http://www.amazon.com/gp/product/1935182501/