[Solar-talk] Event Handler simplest implementation
Rodrigo Moraes
rodrigo.moraes at gmail.com
Sun Nov 26 07:59:53 PST 2006
On 11/26/06, Travis Swicegood wrote:
> Now your callbacks can be anything without having to implement a
> specific method API - just something that's callable (functions, objects
> that act like functions (i.e., static methods), real objects, etc.).
This is more interesting indeed for a base class. Maybe mine was not
as simpler because I started it adapting to work with code that I was
using already, but I can now follow you suggestions, which are nice.
(I'll in the way to build tests for it)
> You'll note that I'm passing in $object - I'd make the default behavior
> to be pass the object that's calling the notification as your parameter
> so the observing object would have access to whatever triggered the
> event and could use/modify it.
That's was the approach I was using, but in many cases you need to
pass flags and other objects to the observer, and then I started to
pass the object calling the notification inside an array together with
other data. There is no problem to pass only the caller - it can then
have (or not) public methods so the observer can get and set the data
& flags it needs. I'll follow this more 'pure' approach too.
thanks for the feedback.
rodrigo
---------------------------------------------------------------------
Solar has now a Community Wiki: solarphp.org
---------------------------------------------------------------------
Join the #solarphp IRC channel on freenode.org
---------------------------------------------------------------------
More information about the solar-talk
mailing list