Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What pattern is this??? 2

Status
Not open for further replies.

Craig0201

Technical User
Oct 11, 2000
1,261
GB
I need to create a collection. The rules by which the objects in the collection are created and added are dynamic.
There may be one or more rules to use.

It's like advanced Builder from what I can gather but how to go further is puzzling me, somewhat.

Thanks for the help in advance.

Craig
 
Sounds like it might be strategy that you need. Can you be a bit more specific?
 
I have a collection which applies in a number of circumstances and is composes part of a number of objects.

Each of these objects needs to be able to build a collection. But additionally, the return collection needs to be (pre-)filterable by any number of parameters.

Does that make any sense?

Or need more details?
 
I am not following...
"Each of these objects needs to be able to build a collection."

lost me

 
OK, i'll try again. Bear with me.....

I have a set of objects, each representing an actor in the system. Each of these actors needs to build a collection of historic events which they have acted in. This collection of events then needs to be filterable according to parameters such as a time period.

I suppose it's a bit like being able to build a stored procedure where the WHERE clause has a massive, if not infinite, number of possibilities.

Some sort of repository style object with rule objects added to a rules collection to return the collection of events?
 
Is the filtering done on a set of common parameters for each actor? Or do the different types of actor support different filter criteria?

Also, how often will it run, and how big is the database it runs against? This may affect how we approach the problem - a set of rules that construct an SQL query and then execute it is fine if we don't need to do it several hundred times a second.
 
There are a finite number of parameters with which to filter by. There is no reason that I can see why each of these filter could not be applied by each of the actors.

The db is approximately 1.5 million separate events. There will not be hundreds of these running a second by any means, more likely in the realms of hundreds per day!

Would building a SQL clause from a set of rules be a reasonable approach?

Is this then Command taking a Composite command?

Or is that my brain frazzling?
 
A good analogy for a composite command is a macro; a series of commands grouped together so you can call them with a single command. This isn't it.

I think this is probably a strategy pattern. You can prepare a FilterCriteria object (as they are all the same) and pass it to the GetFilteredReport() method of your actors. Different kinds of actors may use different strategies to produce the report. The caller doesn't need to know what kind of actor it is.

On building the SQL command, you might want to consider validating the parameters in some way - for example, we don't want to allow the users to do a wildcard search on an unindexed column with no other parameters, as this will cause us to search all 1.5M rows. Perhaps the columns that identify the actor could be indexed, or even a part of the key - this would limit the number of rows searched, as each actor could set these parameters based on its identity.

HTH

Steve
 
Cheers Steve.

That was sort of what I thought.

Thanks.
 
Here's an alternative idea. Just my 2 cents, maybe thats all it's worth. Mine is more of a fine-grain approach, over which may be wrapped by a coarse-grained api, like strategies/facades..

What you're essentially trying to do is query data based on filters. Why not create a mini query language? Build queries, hand them to a repository for satisfaction. Repositories interperet the Query into SQL/Xpath/XQuery (strategy intepreters) and asks a DAL to find data.


IQuery aQuery = new Query();
aQuery.Add(new Constraint("Age",25));
aQuery.Add(new Constraint("FirstName","Kevin"));

People[] somePeople = PeopleRepository.FindAllBy(aQuery);


Edward J.S

 
Edward,

I like that approach.

If I did the query language carefully, this would be reusable. So indeed, this makes good sense.

Thanks,

Craig
 
yeah, the above is a simple example. Query languages can get pretty complicated:

IQuery = new Select(
new And(
new Constraint("Age",25), new Constraint("Name","Joe")
)
)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top