开发者

What is Loosely Coupled Code?

开发者 https://www.devze.com 2023-04-02 08:22 出处:网络
I recently learned Ruby and Rails, I come across开发者_开发技巧 these terminologies, that I can\'t understand off the bat.

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.


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号