Re: Re: Subject/Observer design pattern in PEAR
| From: | Hans Lellelid | Date: | Thu, 22 Jul 2004 11:35:04 +0000 |
| Subject: | Re: Re: Subject/Observer design pattern in PEAR | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-32245@lists.php.net to get a copy of this message | ||
Hi Heino,
I'm glad you jumped up & proposed a package!
Heino H. Gehlsen wrote:
Maybe there should be an Iface Category ... ? I don't know how many of these things are really expected. Unlike packages, the more there are the less useful they are, really.Why this "Util" prefix?Why not? As clearly stated in the proposal description, this code is based on private purpose code. I merely choose not to change the unimportant stuff, since I really didn't care much in which category the code might end up in....
I agree -- definitely classhints would be the way to go here. That's really the nice thing about using interfaces with PHP5. I think it's ok for the error to be fatal, because code must implement the interface (no need to extend a base class or anything). The thing that needs improvement is that error itself & that is something for PHP internals folks to improve. (it has come up & there was support for adding a reference to the calling code, so I anticipate that this will get fixed)If you'd use ClassHints you could strip most of the throw statements.
Yup, this is the design of interfaces. You do have to implement them. Certainly you don't have to extend any base classes, though.Even the need to extend a class to implement the observable pattern limits way too much in my opinion.You wouldn't *have* to extend the class, since you could of cause implement the interface in any class - that's the beauty of interfaces, isn't it? The class is only meant as a base class, which one could choose to extend or not. It's all about the interfaces!
While I agree with Michael that the attach/detach/notify seem a lot more prevalent in the observer patterns I've encountered/used, the propsed addObserver-style method names are certainly very clear. Cool work! HansI'd much more appreciate the commonly used API for observers:interface Observable { public function attach[Observer](Observer $Observer); public function detach[Observer](Observer $Observer); public function notify($Note); }