Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to design a business logic layer

To be perfectly clear, I do not expect a solution to this problem. A big part of figuring this out is obviously solving the problem. However, I don't have a lot of experience with well architected n-tier applications and I don't want to end up with an unruly BLL.

At the moment of writing this, our business logic is largely a intermingled ball of twine. An intergalactic mess of dependencies with the same identical business logic being replicated more than once. My focus right now is to pull the business logic out of the thing we refer to as a data access layer, so that I can define well known events that can be subscribed to. I think I want to support an event driven/reactive programming model.

My hope is that there's certain attainable goals that tell me how to design these collection of classes in a manner well suited for business logic. If there are things that differentiate a good BLL from a bad BLL I'd like to hear more about them.

As a seasoned programmer but fairly modest architect I ask my fellow community members for advice.

Edit 1:

So the validation logic goes into the business objects, but that means that the business objects need to communicate validation error/logic back to the GUI. That get's me thinking of implementing business operations as objects rather than objects to provide a lot more metadata about the necessities of an operation. I'm not a big fan of code cloning.

like image 262
John Leidegren Avatar asked Nov 03 '10 09:11

John Leidegren


People also ask

What should be in business layer?

The Business Layer is the place where all the business/domain logic, i.e. rules that are particular to the problem that the application has been built to handle, lives. This might be salary calculations, data analysis modelling, or workflow such as passing a order through different stages.

What is the use of business logic layer?

In programming, the Business Logic Layer (BLL) serves as an intermediary for data exchange between the presentation layer and the Data Access Layer (DAL). The Business Logic Layer handles the business rules, calculations, and logic within an application which dictate how it behaves.

How do you create a business layer in Visual Studio?

In the solution explorer, right-click on "References" of your web project and select "Add Reference...". From the tab "Projects", choose your business layer project and click "OK". This reference allows you to access public classes and methods of the business layer. Copy the connectionStrings section from the App.

Which architecture has business logic layer?

A multitier architecture formalizes this decoupling by creating a business logic layer which is separate from other tiers or layers, such as the data access layer or service layer. Each layer "knows" only a minimal amount about the code in the other layers—just enough to accomplish necessary tasks.


2 Answers

Kind of a broad question. Separate your DB from your business logic (horrible term) with ORM tech (NHibernate perhaps?). That let's you stay in OO land mostly (obviously) and you can mostly ignore the DB side of things from an architectural point of view.

Moving on, I find Domain Driven Design (DDD) to be the most successful method for breaking a complex system into manageable chunks, and although it gets no respect I genuinely find UML - especially action and class diagrams - to be critically useful in understanding and communicating system design.

General advice: Interface everything, build your unit tests from the start, and learn to recognise and separate the reusable service components that can exist as subsystems. FWIW if there's a bunch of you working on this I'd also agree on and aggressively use stylecop from the get go :)

like image 181
annakata Avatar answered Oct 01 '22 13:10

annakata


I have found some o fthe practices of Domain Driven Design to be excellent when it comes to splitting up complex business logic into more managable/testable chunks.

Have a look through the sample code from the following link:

http://dddpds.codeplex.com/

DDD focuses on your Domain layer or BLL if you like, I hope it helps.

like image 39
Burt Avatar answered Oct 01 '22 13:10

Burt