Skip to main content
2 of 3
added 234 characters in body
Doc Brown
  • 220.5k
  • 35
  • 410
  • 625

Creating interfaces for classes as well as placing them in a certain component is not an end in itself. It creates extra effort and boilerplate code, which needs to be justified by some purpose.

So the first question you need to ask yourself here is: which purpose do you want to achieve? For example, unit testing is a typical goal. But unit testing alone the scetched classes does only require interfaces, not necessarily in separate components. Still, isolation at the component level can make testing more simple or faster or less costly. Hence you need to decide if you want the classes CA and CB testable in full isolation from each other, so tests for CA, which may need to implement a mock for CB using the interface IB dont even have to include the component B? Or is including the component B for a test cheap and hence acceptable?

If you think you need full isolation in both directions, none of your designs seems to be sufficient - for this, one will have to introduce extra interface components, either one layer for all interfaces, or an individual interface component for each interface. But beware, such a split-up causes extea maintenance effort, hence you should have a real need for it.

Doc Brown
  • 220.5k
  • 35
  • 410
  • 625