Originally posted by SpontaneousOrder
View Post
If you have complicated logic in A coupled to complicated logic in B, then most of the time you've got a bad design. If you have complicated logic in A coupled to more trivial logic in B, then testing A & B together with a mocked C is often even better.
There is a time and a place, which is the point being made. Getting more benefit from isolating a single class, as opposed to from a small gaggle of cohesive classes operating together is, in my opinion, fairly rare. Hence I'd expect to see things like factories which return pre-assembled components being injected more than I would expect to see every single dependency being wired up in some layer of indirection.
There is a time and a place, which is the point being made. Getting more benefit from isolating a single class, as opposed to from a small gaggle of cohesive classes operating together is, in my opinion, fairly rare. Hence I'd expect to see things like factories which return pre-assembled components being injected more than I would expect to see every single dependency being wired up in some layer of indirection.
A good example for isolating classes might be if B is a UserPreferenceService, and A reads out a preference which is then used to drive some further logic in A.
How can you verify how A behaves correctly based on all the possible return values for this preference?
How can you confirm A behaves gracefully if B throws an exception, return null, returns garbage, or doesn't return at all?
Comment