laziness, impatience, and hubris | |
PerlMonks |
Re: OT: Design questionby Joost (Canon) |
on Sep 30, 2004 at 18:18 UTC ( [id://395440]=note: print w/replies, xml ) | Need Help?? |
Your names are confusing to me. In my eyes, assuming that the only thing that really determines the event and its parameters is the widget, the widget is the event. So let's call the widget $event, and the events event_handlers. What I would try to make is a main handler like this:
As you can see the main code doesn't actually try to do anything with the innards of either $event or $handler. I'm just making the easiest interface I can think of, and I'm trying to keep all the implementation details out of the main code. Now @event_handlers can contain objects or classes, or a mix of both, it doesn't matter, as long as each of them has a handle() method that accepts an $event (or $widget, if you prefer) parameter. This makes the @event_handlers themselves responsible for parsing and processing the widget. You probably don't want to copy a lot of similar code to all the different event_handlers, so the $handler classes can inherit from some base class if that seems useful, or they can share code by calling to some other class. (update: or they can be objects of the same class, as demonstrated further on in the thread) As for setting up the classes, let's say all event_handler classes are named Handler::SomethingOrOther, and you put each in its own SomethingOrOther.pm file in the /my/event/handlers/Handler directory:
I'm assuming all @event_handlers are classes and not objects, but if you need to you can replace that push statement with to create objects instead. Have fun. Joost.
In Section
Seekers of Perl Wisdom
|
|