Skip to main content
added 108 characters in body
Source Link
Doc Brown
  • 220.5k
  • 35
  • 410
  • 625

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

The fact the transitive dependency from CustomerController to UserService by UtilityService manifests itself explicitly as a direct dependency is not an issue, as long as it is not a design goal to make UtilityService a facade for accessing the service layer by the controller layer. The examples you gave show no indication for this.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

This answer shows how to resolve any kind of cyclic dependency by introducing interfaces. This answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

Note also resolving cyclic dependencies is not an end in itself, it is means to an end. A certain amount of cyclic dependencies (within one layer of a layered architecture, of course) can be acceptable, as long as testability and build times are not affected too much.

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

The fact the transitive dependency from CustomerController to UserService by UtilityService manifests itself explicitly as a direct dependency is not an issue, as long as it is not a design goal to make UtilityService a facade for accessing the service layer by the controller layer. The examples you gave show no indication for this.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

This answer shows how to resolve any kind of cyclic dependency by introducing interfaces. This answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

The fact the transitive dependency from CustomerController to UserService by UtilityService manifests itself explicitly as a direct dependency is not an issue, as long as it is not a design goal to make UtilityService a facade for accessing the service layer by the controller layer. The examples you gave show no indication for this.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

This answer shows how to resolve any kind of cyclic dependency by introducing interfaces. This answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

Note also resolving cyclic dependencies is not an end in itself, it is means to an end. A certain amount of cyclic dependencies (within one layer of a layered architecture, of course) can be acceptable, as long as testability and build times are not affected too much.

added 108 characters in body
Source Link
Doc Brown
  • 220.5k
  • 35
  • 410
  • 625

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

The fact the transitive dependency from CustomerController to UserService by UtilityService manifests itself explicitly as a direct dependency is not an issue, as long as it is not a design goal to make UtilityService a facade for accessing the service layer by the controller layer. The examples you gave show no indication for this.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

This answer shows how to resolve any kind of cyclic dependency by introducing interfaces. This answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

This answer shows how to resolve any kind of cyclic dependency by introducing interfaces. This answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

The fact the transitive dependency from CustomerController to UserService by UtilityService manifests itself explicitly as a direct dependency is not an issue, as long as it is not a design goal to make UtilityService a facade for accessing the service layer by the controller layer. The examples you gave show no indication for this.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

This answer shows how to resolve any kind of cyclic dependency by introducing interfaces. This answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

added 108 characters in body
Source Link
Doc Brown
  • 220.5k
  • 35
  • 410
  • 625

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

The second highest voted answerThis answer shows how to resolve any kind of cyclic dependency by introducing interfaces. The accepted answerThis answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

The second highest voted answer shows how to resolve any kind of cyclic dependency by introducing interfaces. The accepted answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

The premise of this question is wrong - the example does not show a circular dependency.

The dependencies are

 CustomerController | | V | UtilityService | | | | | V V | UserService V ContactService 

This is a directed acyclic graph - there are no cycles involved.

For code, however, which really contains circular dependencies, have a look at this older SWE.SE question: How to solve circular dependency?

This answer shows how to resolve any kind of cyclic dependency by introducing interfaces. This answer shows how cyclic dependencies can be avoided in certain cases by creating smaller components with less responsibilities.

deleted 3 characters in body
Source Link
Doc Brown
  • 220.5k
  • 35
  • 410
  • 625
Loading
Source Link
Doc Brown
  • 220.5k
  • 35
  • 410
  • 625
Loading