views:

110

answers:

1

Hi,

I find that whenever I create a layer/tier, I have to translate between one layer to the other, does that mean it is a tightly coupled system? If I was to change a business logic, remove a field in the database, etc, I would have to change ALL layers from the database layer to the client front end?

E.g. A web service that exposes a "data contract" object, and converts it to some "business objects" in the middle layer, then converts it to the appropriate "ORM object" in the data layer. And the client calling the web service, converts the datacontract to some model objects, etc...

Since there are so many translations in between, how can web services be designed to be loosely coupled? Just getting my head around it, if someone can share his/her opinions it would be great.

Thanks

+2  A: 

Translation or mapping is orthogonal, although somewhat related, to loose coupling.

  • If you map from concrete type to concrete type the mapping is tightly coupled
  • If you map from abstract type to concrete type or the other way around, the mapping is loosely coupled

In other words, loose coupling is related to the concept of programming to interfaces - not to mapping.

If layers in an application communicate with each other through concrete types, it's tightly coupled. In such a case, layering doesn't provide much value, and you might as well have built a monolithic application.

On the other hand, if a layer communicates with other layers through interfaces the layers will be loosely coupled, but mapping is often still required.

Mark Seemann
If you map from abstract type to concrete type or the other way around, the mapping is loosely coupled.I accept that it is in a way loosely coupled looking from the point of view from an interface, but it can still be tightly coupled to the database table fields? for example, if you remove a column in a table, what happens then? You would need to change the interface and mappings, aka, in a way, coupling? Multi layer = multi translations and propagates all the way up the layers, maintenance increases, so is it still loosely coupled?
Titan
Adding or removing data (whether in the database, or as members on .NET types) are to be regarded as contract changes. That can hurt more in a loosely coupled system because of the multiple places in which you need to implement this change, but on the other hand you may also be able to isolate yourself against changes in other layers. It depends on why you introduce the change, but it's not what we normally understand from the concept of loose coupling.
Mark Seemann