Conditional or Rules based processing

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Conditional or Rules based processing

Post by BDKR »

Hey kids,

I'm developing a reservation (equipment, meeting rooms, etc...) system here at at work and am interested in some feedback eventhough I'm pretty 80% convinced that the design in my head will work fine.

Anyway, this reservation system is something that will most likely be used amongst many different groups. Each of these groups having their own bits fo stuff to loan out and their own rules or policies to govern this. Now there is no way to write one bit of code that is going to work for all of the different groups. It's obvious that I need a rules or policy basd algo. Here is what I've come up with.

1) A table that stores the rules based on the groups they belong too and the type of rule it is (type is enum).
2) Each line/rule in the table will have a rule_processor field. This field is a string representing a call back function.

Keeping the above in mind, when a reservation is in the process of finalization (and potentially at other steps as well), the rules table is interogated for matches. If a match is found, then the corresponding call back function (or method) gets a crack at the submitted reservation data and can manipulate it as needed.

In this way, changing any of the specifics for any of the groups is a breeze over time. :D

BUT KNOWING ME, I'm bound to have forgotten something. :oops: That said, I'd love to hear any takes on this scheme above.

Cheers,
BDKR
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I'm not sure I have much to say on the matter. It's pretty specific in nature, not generic application architecture, etc.

One thing I will say for sure is that using a rules/policy algorithm would obviously be best or better than hardcoded conditionals. Beyond that I am not sure what more to say without some fore-thought or seeing your code in action.

Can you give some examples (highlevel; pusedo English) of a rule?

The callback or methods which are invoked and bound to each rule obviously house the conditional logic. But what does a rule table look like? What kind of questions does it answer?

Is it possible using your system to define multiple types of reservations at runtime?

For example, could be tweaked to say:

1) Reserve a car
2) Reserve a hotel

Each would require a finite number of rules. The one common field would be checkin-date & checkout-date but for car rentals one may wish to rent a car based on estimated travel distance. Whereas a hotel one might require a bar fridge and jacuzzi.

How does your res. system handle these kind of situations?

Cheers :)
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Hockey wrote: Can you give some examples (highlevel; pusedo English) of a rule?

I think a good example of a rule would be something like....

1) If an item / resource is reserved on the same day it's requested it .....
a) can't be garaunteed
b) can't be picked up before a certain time

Pretty simple, but it's of use.
Hockey wrote: The callback or methods which are invoked and bound to each rule obviously house the conditional logic. But what does a rule table look like? What kind of questions does it answer?
I'd imagine a rules table could have differing looks based on how your choose or need to match rules and the makeup of your orginazation. In our case, there are many different groups with their own resources. That said, we're forced to use an identifier for the individual groups. Therefore, I'm choosing to interogate the table based on the group and the resource type at this point in time.
Hockey wrote: Is it possible using your system to define multiple types of reservations at runtime?

For example, could be tweaked to say:

1) Reserve a car
2) Reserve a hotel
That's the idea. Since this post, I've implemented the rules table and it's allready working as hoped. I believe the rest of the system is just about extensible enough to be completely functional. It definitely is at the UI level. I'm just trying to make sure I cover enough bases at the logic level to make it so.

Cheers
Post Reply