Question

I recently learned Ruby and Rails, I come across these terminologies, that I can't understand off the bat.

So Please explain, ( with analogies, if possible ) what is Loosely coupled Code.

Was it helpful?

Solution

A Lay Man's Explanation,

You have two classes, Class A and Class B that probably interact together. if they are loosely coupled, Class A would do what it is supposed to Do(what you want it to do) without knowing the details of Class B's Implementation

Hope it makes some Sense?

OTHER TIPS

loose coupling basically means that you want the components of your program to connect easily with other components, this was you can enjoy code reuse and make things more efficient, e.g., there are Design Patters like MVC (Model View Controller) that help you with separation of concerns, you can have some of your code responsible for the GUI and some other code responsible for the access to a database, and if you want to change any of these parts you want them to avoid being too dependent on each other, i.e., that's why you should rely on interfaces instead of implementations, you want to make things easier because software is always changing/evolving.

Usually loose coupling is mentioned along with the concept of "High Cohesion", this one can be subjective but it's nothing more than writing code that makes sense and design your components in a way that will facilitate understanding, maintenance, extensibility etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top