Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Rule of thumb is always: if you need it, do it, otherwise, don't. Real world cases could be:

1. If you write a unit tests and really need to have a double of that particular component, then do it. Otherwise, don't.

2. You need to decouple the dependency (maybe these are circular), then do it. Otherwise, just take on it as a dependency.



#2 is interesting...can you give an example solving circular dependencies? Even if you had an interface, wouldn't you still have the implementations still causing a circular dependency?


You can turn A->B, B->A into A->I,B->A + A.I=B and that does avoid a circular dependency.

A->B means a depends on B, A->I means A depends on an interface, and A.I=B means that B is set as the implementation of the I interface that A depends on.

I’m on mobile so that was the best I could come up with. Try it out using Swift though, and that can be translated pretty directly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: