|XP is just a number|
OT: Design questionby dragonchild (Archbishop)
|on Sep 30, 2004 at 17:32 UTC||Need Help??|
dragonchild has asked for the
wisdom of the Perl Monks concerning the following question:
I have been tasked with rebuilding a system to track widgets (what I'm tracking is irrelevant). This subsystem is an XML-RPC server with a very well-defined API. Whenever a new widget is added (through the add_widget() call), there are potentially N actions that need to be taken after the widget has been successfully inserted into the database. For example, if a green widget is added, a specific person needs to be emailed, or whatever.
Every widget is based on a widget type. Each widget type has a specific number of properties (color, size, etc). The events trigger based on the properties of the widget type.
Now, the events will be pre-made, but there are currently over a hundred events. Some widget types have no events that trigger on them, but some might potentially trigger up to 5 (or more) events. There is no constraint on the number of events the addition of a given widget might trigger.
The current system is built around a huge if-elsif-else statement that is around 500 lines long, most of which is cut'n'pasted. There's only really about 4-5 different types of events, just with different parameters. The business wants to triple the number of widget types being handled, adding at least another 10-20 different types of events. (It's important to note that each event type will take completely different parameters.)
So, it's relatively obvious that the if-elsif-else option isn't viable in the long-term. I was thinking about creating an event system, based on the following high-level design:
Here's the problem - how do I structure this? Assume that the people who will maintain this are Perl gurus, so any feature is usable. My thoughts are going down the following paths:
It's a messy situation. If I go with objects and a config file, I have to specify the event type and all the necessary parameters. Do I just die if the config file is mis-configured? If I go with the database option, how do I source-control it?
If I go with a class for each specific event, I now have hundreds of classes, most of which will look extremely similar. That sounds even worse than the if-elsif-else option!
Update: I don't think people are understanding the question I'm trying to ask. I already know I'm going to be using a set of callbacks for the event handlers. Those callbacks are going to register with the add_widget() function in some fashion. My question is how to deal with the hundreds of callbacks I'm going to have to deal with. Read the exchange I had with Joost for what I mean.
Being right, does not endow the right to be rude; politeness costs nothing.