Pattern wanted...

Posts   
 
    
softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 30-Oct-2008 18:00:07   

Hi guys,

I'm currently implementing my web application's legimitation system.

On a very basic level the underlying database schema is really pretty simple: there are "users" and there are "dialogs". And because a concrete user may only access certain dialogs there is a matching m:n relationship too.

I figured, I will need at least the following methods:

1. DialogCollection GetAllDialogs() 2. DialogCollection GetEnabledDialogs() 3. DialogCollection GetValidDialogs(UserEntity currentUser)

Some explanations: 1. will get all dialogs that are stored in the database, no matter what 2. will get all dialogs that are enabled (there is a boolean field that tells if a dialog is enabled or not) 3. will get all dialogs, that are enabled and for which a given user is legitimated

There are lots of different aspx-pages that need access to these methods, so I need them on a "global application level".

First I was thinking to just create a static class and implement these methods as public methods. However, if you look at the explanations again, you will surely notice that the methods are somehow related.

For instance: if you are asking for the valid dialogs one approach could be to first get all available dialogs, then reduce this collection to the enabled ones and finally kick all those out for which the given user is not legitimated. In other words: No. 1 would be using No. 2 would be using No. 3

So here is where I need your advice: First of all, I realize this might not be a real LLBL issue. On the other hand I was wondering if any of you guys had a good idea on how to implement this in a clean object-oriented way...based on LLBL entities and collections. Should I just create three classes and use one class as an input for another one?

Perhaps the whole thing can be solved way better by a common design pattern? Unfortunately I don't have enough experience in design patterns, so I just don't see "the pattern" (if there is one).

I really hope someone can help me out here! And of course, please feel free to ask if I can provide you with more information.

By the way: my real application is a more complicated than the above. So don't you wonder why I made a mountain out of a molehill by asking for your advice on the above. I just stripped "the real world" down a little bit so it would be easier to understand. But having a good solution for the above, I believe I could solve the "real world" myself.

Thank you so much for any help! Ingmar

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 05-Nov-2008 12:05:06   
  1. DialogCollection GetAllDialogs()
  2. DialogCollection GetEnabledDialogs()
  3. DialogCollection GetValidDialogs(UserEntity currentUser)

If you are going to call all of the above methods in each page, then you may only go to the database once in rhe first method to fetch all the Dialogs then consequently you should use the fetched collection in the second method to be in-memory filtered using an EntityView, and the so on for the 3rd method.

A similar question about step by step filtering was asked here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=14637

And then comes the question of where to implement these methods, it looks like 3 static methods in a static class might be the good option. But again if these are going to be called in each page, and I doubt that the results will change from a page to another. Then I suggest to call these methods only once on Session start, and store the results in the session to be read in each page. In fact "all Dialogs" and "enable dialogs" can be stored as an application variables, since they look common for all users, and only user "ValidDialogs" should be stored in the session.

So if my assumptions are correct, you should call the first couple of methods in application start and store their returns in applications variables. And in Session start you should call the thirsd method to store its result in a Session variable.

softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 05-Nov-2008 12:27:42   

Thank you very much Walaa!

The similar thread you mentioned was from me too. So, with your help I could already solve this in the way you suggested.

Thank you again! Ingmar