Class and component dependency cycles
Assume, we have component A
with class CA
, and component B
with class CB
, with a cyclic two-way dependency between classes CA
and CB
. Hence, we have a cyclic dependency between components A
and B
.
Resolving class dependency cycle
A standard way to resolve the class cycle is to introduce interfaces (e.g. IA
implemented by CA
in A
and IB
implemented by CB
in B
) and let the classes depend on the interfaces. Now, there are no dependency cycles between the types, but still between components.
Resolving component dependency cycle
On frequently suggested idea (e.g. by Robert Martin) is to move one of the interfaces to the other component, e.g. component A
with class CA
and component B
with class CB
and both interfaces.
Issues with the approach For somebody who is used to have interface and class in the same component, this feels unnatural because they seem to belong together. Probably I am thinking too much in terms of what services a class is offering and then extracting the interface instead of what services consumers require and let the implementation be completely independent in my mind.
Question I am looking for more reasons why it is a good idea split up interface and implementing class into separate components?