Here’s the requirement;
“Make this product available for ordering to clients of (category
1) or (of age over 24 and not in region A)”
The above seems like a SQL query, but it really is not. Ok!
maybe it is. In reality it’s a DSL that will act as a filtering engine. Here’s the thing, I have a catalogue of
products that I want to make available to specific clients. Much like we see in
pricing rules in e-commerce platforms I would like to give the end user capabilities
of creating these rules. So the final
result should be a dynamic catalogue displaying exactly what I tell it to
display depending on the user.
It really is like an e-commerce up sale, cross sale except
that it’s the end user that creates these rules, not the actual sales.
Normally I would pull together some “if else” statements and
encapsulate it into a class and voila. But then I remembered that my client not
only uses these kind of rules to limit what kind of product can be available to
whom, I also discovered that in a different modules he uses a messaging system
that are sent using exactly the same rules. So we can easily transform the
above DSL into something like this:
“Send a message to clients of (category 1) or (of age over
24 and not in region A)”
So I decided to write something reusable that will be used
on the application level rather than module level.
A year ago I decided to invest more into learning design
patterns, so my mind is eager to use more design patterns to solve my problems,
fully aware that design patterns can be more like a thorn in the side if not
used properly, however I also became aware of their capabilities. And something
is telling me that Design pattern is the way to go in this case.
I have been trying to find the suitable pattern for this
particular problem and I think I narrowed it down to GoF Interpreter pattern.
Other suggested that I use WF but I’m leaning more that the GoF pattern.
Now the real problem comes; even if I know what the problem
is, and what pattern I should be using to solve it, I still have no clue where
to begin and how to code it! I could not find a decent example on the web to
base myself on it.
I am hoping that the members of this forum can point me in
the right direction, since I’m fairly new to design patterns.
Although I’m pretty sure that the Interpreter pattern is the
suitable one, but I would be more that grateful if you think that there are