views:

125

answers:

2

In an N-Tier app you're supposed to have a business logic layer and a data access layer. Is it bad to simply have two assemblies: BusinessLogicLayer.dll and DataAccessLayer.dll to handle all this logic? How do you actually represent these layers. It seems silly, the way I've seen it, to have a BusinessLogic class library containing classes like: CustomerBusinessLogic.cs, OrderBusinessLogic.cs, etc. each calling their appropriately named cousin in the DataAccessLayer class library, i.e. CustomerDataAccess.cs, OrderDataAccess.cs.

I want to create a web app using MVP and it doesn't seem so cut and dry as this. There are lots of opinions about where the business logic is supposed to be put in MVP and I'm not sure I've found a really great answer yet.

I want this project to be easily testable, and I am trying to adhere to TDD methodologies as best I can. I intend to use MSTest and Rhino Mocks for testing.

I was thinking of something like the following for my architecture:

I'd use LINQ-To-SQL to talk to the database. WCF services to define data contract interfaces for the business logic layer. Then use MVP with ASP.NET Forms for the UI/BLL.

Now, this isn't the start of this project, most of the LINQ stuff is already done, so it's stuck. The WCF service would replace the existing DataAccessLayer assembly and the UI/BLL would replace the BusinessLogicLayer assembly etc.

This sort of makes sense in my head, but its getting really late. Anyone that's traveled down this path have any guidance? Good links? Warnings?

Thanks!

+1  A: 

the way I've seen it, to have a BusinessLogic class library containing classes like: CustomerBusinessLogic.cs, OrderBusinessLogic.cs, etc

Ouch. Get and read Scott Ambler's "Building Object Applications That Work". Your approach does not and is a maintenance enightmare - no objects.

I'd use LINQ-To-SQL to talk to the database. WCF services to define data contract interfaces for the business logic layer. Then use MVP with ASP.NET Forms for the UI/BLL.

Yes. Great way to make the application artificially more complicated and slower than it has to be. Throw out the complete WCF service - what are they for? WCF is for SOA, and SOA lives in the user interface (i.e. it is a trust boudary and a user interface for another application to use). Unless you have that requirement.... it is stupid tointroduce additional slow technologies that just have overhead.

The WCF service would replace the existing DataAccessLayer assembly

The Daily WTF - what the heck do you have a DAL assembly for when you use LINQ to SQL? LINQ to SQL (the runtime) is your DAL.

Anyone that's traveled down this path have any guidance? Good links?

You basically picked every antipattern I can think of - maintenance nightmare, overdesigned with tons of useless technologies in there. You force layer technologies into a tiered architecture.

Read the book I mentioned.

TomTom
Thank you Tom Tom, disregard my post other than my planning. i'll pick up a copy of the book you mentioned.
PieterG
Thank you for your answer. It was a little harsh but I supposes its a sign that you have such strong feelings. However, please note that this is not my design.I was thinking WCF would be a good way to go. It seemed like it fit, but you're right, it would add unnecessary overhead.To answer your "Daily WTF", we have a LINQ assembly that contains our entites and the DAL contains our API to the LINQ layer. But then a lot of the BLL logic seems to just be stubs calling the DAL. These layers could probably be merged into a single service layer (hence my thought of WCF. *sigh*
whatispunk
The answer was honest and correct. Any harshness in the answer seems to be warranted. What do you need a service layer *for*? Why does it need to use a communications channel? Why is your business logic *not* in your model objects? Why do you insist on referring to LINQ to SQL as a "DAL" when it is supposed to be your transparently persistent domain model? There is far too much stuff in there, and so far as anyone on SO knows, there's no reason for most of it. This all may make sense in your head, but I cannot fathom why you would want to deal with all that cruft.
Justice
Time for some honesty. This isn't my design. I agree with every harsh statement made thus far. I'm known in my office as a sh*t disturber because I always voice my opinions on how to change/improve the design, but I'm often ignored because the changes either affect deadlines or are simply too drastic or difficult. The "service layer" is actually a bastardization of an idea I had once. I'd prefer to see the DAL as a set of repositories and the BLL as a proper domain model or a set of controllers/presenters. Please help me understand why this is bad design so I can provide a suitable argument.
whatispunk
A: 

About the XXXBusinessLogic, they become God Objects very quickly. Think in objects that make sense in your domain that represent the behavior, not in BusinessLogic "objects". These sort of "objects" will end performing ALL the work for XXX, and yes, they are a maintenance nightmare.

bloparod