Web service for business logic or data access layer

business-logicdata-access-layerweb services

This post http://www.theserverside.net/tt/articles/showarticle.tss?id=Top5WSMistakes
encourages me to create the web service for business logic layer but many people use it in the data access layer.

I want to create a project where i want to access the same data repository from a desktop application, website and a cell phone. What would you recommend me?

Is there any case it may be a good idea to implement web services to both layers?

Best Answer

The question is too open ended so the answer is: it depends.

What needs do your applications have for the data? Is it just data access or some business logic involved? If it is just accessing of data, do you really want the client to have direct control over it? How similar are the three applications? Do they share functionality or just data?

As I see it there are two main paths you can chose:

1 - expose a web service for the business, with the data hidden behind the web service. This is a good setup if the three clients (I'll call the desktop app, web app and cell phone "clients" since that is what they are) share functionality (i.e. they are different views for the same business model). This avoids duplicating similar business logic in all the clients;

2 - expose the data directly with a web service. This is a good setup if the three clients have nothing in common but just use the same data for different purposes. But in this case, with the three sets of business logic, where are you going to put the logic? In the clients? How will that work for the desktop application (considering you install this desktop app 300 times or so)? You again need some service and the clients to be thin clients not thick ones.

If you take 1) and 2) into consideration you will see that usually it is better to have a service layer in front of your data.

Going back to the "it depends", analyze your special needs first and only then choose the solution that is best suited for your situation.

How about a point 3? make your data access layer into a library (.jar, .dll or whatever technology you are using) and make that available to the (1? 2? 3?) business web services that serve your clients?

Related Topic