Business Logic Seperation

Posts   
 
    
mduke
User
Posts: 5
Joined: 02-Jul-2007
# Posted on: 03-Jul-2007 02:16:35   

Hello all!

First let start off with an appology for this being a total newbie issue. i am fairly new at the whole OOP thing as well so please take it easy on me as i still dont have a lot of the jargon down pat.

i have been forced into writing classic VB code (and VBA) and classic ASP using VBScript for the whole of my programming life due to me coming in on a massive ongoing project that was started this way. i have always been a fan of the OO style of programming and have pushed for this way to be taken up for future projects. the time is finally here where i was given the task to deveop a whole new approach for all future products (as well as re-writing our existing ones using the new framework i develop). i quickly realized that LLBLGen Pro was the answer to at least our DAL, which up until this point has been almost completly defined using SPROCS.(which of course contain most of the BL as well).

Anyway, now that the backgroud stuff is out of the way, let me try to get my question out in a semi-coherent manner.

The Facts: .NET 2.0 VB ASP .NET LLBLGen Pro 2 Adapter Template (whatever shipped w/ LLBLGen)

First i am having a problem in the area of BLL seperation. i have read numerous threads and this seems to be a quite common painpoint for many a developer. i still am having a time wrapping my head around it all.

what i need is to develop a robust data solution for our database. obviously LLBLGen does a great job at this. i am just trying to figure out how to build upon it in a good solid way. this will be the backbone for quite a few different applications that all have the database in common. i could of course create several different LLBLgen projects but that would defeat the purpose of using it to begin with.

i have already decided that i think the Adapter approach is the way to go as that seems to decouple the persitance from the "business objects". what i have a problem with is, where do i implment my code? it is stated in the docs to use partial classes for .NET 2.0 is there an automated way to do this or do i have to do it by hand?

what i need to end up with is a common (to all apps that interface it) interface (dont know it thats the correct term) that my applications all share to access the data.

from what i have read it sounds like a perfect example of the Manager Templates, but then again i have only heard them referenced and no actual tak of what they do. i have seen where to get them but cannot find anythihng on how to use them. Maybe someone could point me in the right direction with these.

the application i am building does quite a bit of searches which will require the proper predicate expressions. i am hoping to have a layer that will alow me to have methods like customer.getCustomersByLastName(szLastName) that will return a collection of customer entities.

i have no problem with all layers being LLBLGen "aware" as some others have mentioned. i nfact i think it would be a wate of time to create different object entities when they are so eleganlty created for you. i just need a way to encapsulate the business logic and expand on what is provided.

I thank you all in advance, i look forward to hearing any comments you have.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 03-Jul-2007 03:26:47   

I am working on a small app that attempts to adhere to the MVP pattern. here's what I have. GUI (asp.net) PAL (presenters & views) BLL (Entity Managers) Model (LLBL Entities) DAL (Adapter)

GUI can see PAL and ORMSupport Classes PAL can see BLL, Model and ORMSupport Classes BLL can see DAL and ORMSupport Classes

I used this post as a guide: http://www.codeproject.com/useritems/ModelViewPresenter.asp

My BLL looks like this Public CustomerManager { public EntityCollection<CustomerEntity> GetAllCustomers() { ... } public CustomerEntity GetCustomerById(int customerId) { ... } ... }

mduke
User
Posts: 5
Joined: 02-Jul-2007
# Posted on: 03-Jul-2007 04:24:30   

Thanks Jason for your quick response.

the info you gave appears to be quite a lot to chew on. i will have to investigate this further. in a preliminary glance the MVP looks like it has a good seperation strategy although it does look like a lot of heavy lifting to get it in play.

i am a little daughnted by this as it is all in C# which i am not that familiar with so following along is a bit of guess work for me.

is there a way to automate the creation of the manager classes and how exactly do you implement them in physical code files? i am sorry that i have a limited understanding of this at the moment i am still fighting a major learning curve.

Thanks for your help, i really appreciate it.

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 03-Jul-2007 13:37:52   

You might want to take a look at how Frans has design helpdesk - see http://www.llblgen.com/hnd/

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 03-Jul-2007 14:48:48   

My current manager classes are written manually. there are only a handful of entities and I only need them for simple data retrievals.

I looked into the manager classes awhile ago. What I found was the mangers just wrapped the adapter and it returned generic types. nothing too fancy. i didn't like this because it put all the responsibility of configuring the query in the PAL.

the biggest differences in C# and VB are:
C# uses braces instead of words
example: { } = if()then/end if, or while()/end while, or foreach()/next
C# uses brackets instead of paranthesis
example: string[] arrayofStrings = new string[2];
Dim arrayofStrings as string() = new string(2)
C# use += and -= to add/remove event handelers and VB use Address of ()
the key words can also be different
using = imports
= Inherits abstract = must inherit

yes MVP can be alot of work to setup. The payoff is unit testing using (nUnit and/or RhinoMocks) and it cleanly seperates what an object is responsible for.

for more information on MVP and testing frameworks google RhinoMocks, nUnit, TDD and Agile development.

As sparmar2000 suggested you should review the HnD source as well. it's not as complicated as the post I referenced, but it does seperate DAL, BLL and GUI.

mduke
User
Posts: 5
Joined: 02-Jul-2007
# Posted on: 03-Jul-2007 16:02:17   

Thanks sparmar2000 and Jason for your help.

i will definantly look into the HnD that may be just what i need.

i appreciate you giving the time to help.

Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 08-Jul-2009 03:52:31   

ASP.NET MVC and LLBLGen

I decided to continue with this thread as it is relevant to my question:

Now that asp.net mvc is released how does the recommendations in this thread and also other threads (http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=12219) fit into an asp.net mvc application.

Eg. Is it correct to say, DAL is the model and BL should be referred to and used from within the controller classes?

Also how does the recommendations change with regards to TDD and NUnit etc.

Overall how does llblgen fit in to the mvc paatern as implemented by Microsoft?

I am using llblgen 2.6 final version; self servicing, two class, C#.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 15-Jul-2009 11:06:22   

Is it correct to say, DAL is the model and BL should be referred to and used from within the controller classes?

Correct, but to be more precise, I'd say the "EntityClasses" is the model.

Also how does the recommendations change with regards to TDD and NUnit etc.

I don't understand what TDD and NUint has to do with the MVC pattern. TDD is a way of development. And MVC is a pattern.

Xiaoluo
User
Posts: 1
Joined: 24-Jul-2009
# Posted on: 24-Jul-2009 14:27:53   

Walaa wrote:

I don't understand what TDD and NUint has to do with the MVC pattern. TDD is a way of development. And MVC is a pattern.

MVC is a pattern that seperates the control from the view. This separation of concerns makes it easier to implement unit-testing.

kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 03-Dec-2009 20:41:42   

Hi guys,

I've a question with using entity classes as a model and business logic separation and recursive saves.

We have two entities in our Model: Folder and File. Folder has a collection of Files. File has a reference to Folder.

Let's say we use manager approach. We have some BL for folders and for files. Where should I put this BL?

If I have two separate managers FolderManager and FileManager and put BL there, than when i pass folder with collection of files to that manager, nobody will call FileManager to execute BL for files (because FolderManager has only BL for the folders).

And vice versa, if I pass File with Folder property set to something, it will just save file with the folder, without going to FolderManager.

So what is the best practice for such cases? Any advices? ideas?

Thanks, Anton

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Dec-2009 05:50:15   

Hi Anton, In Manager classes, is preferred that you don't use circular references between classes, as in FolderMananaer -> FileManager, FileManager -> FolderManager. Instead, you could create a FolderStructureManager, or FileSystemManager (something like that simple_smile ). You can surf the web/books to more info about the best practices on this (some ref: http://martinfowler.com/bliki/LayeringPrinciples.html).

David Elizondo | LLBLGen Support Team