Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is loose coupling? [duplicate]

Tags:

asp.net-mvc

I was studying few concepts of MVC on MSDN, and i reached on a point where they have written a word "loose coupling between the three main components of an MVC".

I searched a lot about the loose coupling on google. But i got different kind of answers every time.

Even i got a new word tight coupling and tight cohesion.

Can anyone define the word properly, and what it means exactly.

I'm looking forward for your replies.

Thanks.

like image 755
Code Rider Avatar asked Mar 27 '13 06:03

Code Rider


People also ask

What is meant by loosely coupled?

Loose coupling is an approach to interconnecting the components in a system or network so that those components, also called elements, depend on each other to the least extent practicable. Coupling refers to the degree of direct knowledge that one element has of another.

What is loose coupling and tight coupling?

Tight coupling means classes and objects are dependent on one another. In general, tight coupling is usually not good because it reduces the flexibility and re-usability of the code while Loose coupling means reducing the dependencies of a class that uses the different class directly.

What is loose coupling in code?

Loose coupling refers to the connection between components of a system or network, such as software applications or hardware. It's an approach in which components (or elements), although connected, aren't dependent on one another.

Why do we need loose coupling?

Loose coupling enables isolation. Components to be deployed independently of one another, giving you much more freedom over when and what you deploy. Cross-functional delivery teams are able get their work done without having to manage any dependencies on other teams.


1 Answers

Loose coupling is simply writing software in such a way that all your classes can work independently without relying on each other. Since you're studying MVC I'll use it as an example to demonstrate the concept of loose coupling:

1) Tight coupling

ASP.NET Web forms are tightly coupled. Each .aspx page is dependent on it's code behind page which makes automated testing a nightmare

2) Loose coupling

ASP.NET MVC is loosely coupled.The logic is separated into 3 parts:

  1. Model - Contains your classes and business logic
  2. View - Displays the application UI based on the model data
  3. Controller - Respond to an oncoming URL request and select the appropriate view

The three parts can be changed independently without affecting one another and thanks to the principle of separation of concern we can easily write automated tests to test our Models without having to rely on Views.

like image 131
Denys Wessels Avatar answered Nov 02 '22 01:11

Denys Wessels