7

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.

4

1 に答える 1

11

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.

于 2013-03-27T15:46:22.443 に答える