Confusion about Business Logic Layer

Posted 18 October 2013 - 07:28 AM

In n-tier i haven't understand a bout BBL.
I will talk a bit about Data Access Layer ( DAL ). ASP.net MVC/webfroms/winforms,Windows Phone.v.v..v.. will use this DAL to manipulate with database ( This mean DAL can be reused on all software platform of MS).

But about BBL. We also build an BLL with methods, then we also reuse it on many sortware platform.
The problem, assume we make an Logout() method ( to logout some thing ). On ASP.net we need to destroy user Session but Winform haven't Session, we just close User Interface ( Forms ). That we have to write new Method => That is not reuse code ( and above thing very non-sense, a method interact with both Web form and win form ).

I'm very confusion about the uses of BBL. What will we do this BLL ? Is "Reuse BLL" a true statement ?

Replies To: Confusion about Business Logic Layer

Re: Confusion about Business Logic Layer

Posted 18 October 2013 - 08:45 AM

LogOut() sounds like a UI method to me, not a Business Object method. You don't log in to an object, you log in to a system. If you want your business objects to dispose of themselves when the user logs out of the system, then the UI's LogOut() method can certainly notify those objects to do so. That's the reusable part: it doesn't matter what the UI's "end session" method looks like (whether a logout button or clicking the "X" in the top-right corner), as long as it makes the appropriate calls to the business objects.

Re: Confusion about Business Logic Layer

Posted 18 October 2013 - 12:32 PM

Depends on whether or not you're referring to each Project (Class Library, MVC Site, etc.) in a solution, or if you're referring to a project in the more general sense, and it also depends on the size of the solution you're working on. A small MVC site can just have everything spread through the folders in the MVC project, without adding separate class libraries and such to the solution. When you get into larger solutions, that's when you might consider moving your business objects into their own Project. It sounds like you could stand to find a good MVC book to read and work through. This is a good book that I recommend.

Re: Confusion about Business Logic Layer

Posted 18 October 2013 - 07:41 PM

If I have a method it generate random number Rand(). Should we put it in BBL ?.
And methods relevant to GUI ( or something like session ( Web only )or form ( winform only ) will we put it in Controller ( of MVC ) or CodeBehind ( ASP.net Web Forms ) ?

Re: Confusion about Business Logic Layer

Posted 19 October 2013 - 08:39 AM

Quote

If I have a method it generate random number Rand(). Should we put it in BBL ?.

Depends on who's using the random number. If a business object needs the random number for something that it does, then let the business object be responsible for creating that random number. If you design your application such that the UI is responsible for supplying it, then you've just created a constraint on what a new UI for the application would have to do (remember, the goal is reusability, so the more design constraints you generate from you business logic layer's design, the less reusable it becomes).

Quote

And methods relevant to GUI ( or something like session ( Web only )or form ( winform only ) will we put it in Controller ( of MVC ) or CodeBehind ( ASP.net Web Forms ) ?

The code that the UI needs to be run should be in the UI. Your model represents that data in your application. The view is where the users can interact with that data. The controllers are like security guard interpreters: they are responsible for allowing access to the data, but ONLY within the constraints that live in the controllers. The view doesn't know what it's allowed to show or let the user change, and the model doesn't know what functionality should be exposed in the application's context. If you were to say that based on all of this, it sounds like session is a UI thing and should therefore be managed by the view, I would agree with you.