Search code examples
oopsoftware-designloose-coupling

When should we prefer hard coupling over loose coupling?


With all the hype about loose coupling (with reason) and all the information ive read its easy to get all obsessed, to the point of becoming religious about it. Ive been wondering, when is hard coupling favorible over loose coupling? When is an object a candidate for hard coupling? I think that depending on the situation it could reduce some complexity.

Some examples would be appreciated.


Solution

  • Advantages of hard/tight coupling

    There are a few scenarios when tight coupling might leave you better off. Typically has to do with speed of development and complexity of the program.

    Very Small Projects/Proof of Concepts

    In the short term, loose coupling increases development time. Theoretically, for every Service/Client pair there will need to be an extra interface created for it as well. Where hard coupling wouldn't even worry about dependencies. From my experience, many projects in school were small enough where tightly coupled classes were okay. Especially in cases when you would turn in the assignment and never have to touch it again.

    Keeping things simple

    Often loosely coupled systems contain more components, which adds more complexity to a program. For bigger programs, the complexity is definitely worth it because expanding/modifying the program will be exponentially easier and cause less bugs. However, for small programs or programs that are 99% unlikely to change, the extra time spent trying to program to abstractions and remove any dependencies, just may not be worth it. Analysis Paralysis is more likely designing a program.

    Concluding Remarks

    As a whole I would never suggest"tightly coupled" classes are better. However, with the interest of time and complexity sometimes "tighter coupled" classes can be justified.