On Wed, Oct 07, 2009 at 11:31:58PM +0100, David Otton wrote:

> 2009/10/7 Paul M Foster <pa...@quillandmouse.com>:
> > I think this is a bit extreme. It really depends on what's in your
> > parent model class. It could be something really simple, but something
> > you don't want to have to rewrite in every model you code. Thinking that
> Have you got an example of something that is needed by every model
> that interacts with a general-purpose framework?

Probably not a great example, but how about this: *Assuming* that the
models need variables held in the config (which database, if any, for
example), we put code in the constructor of the parent model which picks
up these variables and stores references to them, for use in inherited
models. The config could be a singleton class which holds a single
instance of all the config variables. I *could* include a call like

$this->config =& get_config();

in each model's constructor. Or I could just do it once in the parent
model. Of course, if this is all the parent model provides, then 

$this->config =& get_config();

in each model would be roughly equivalent to


in each model. But if the parent provided more than that, then I would
be writing less code to simply build it into the parent. And of course,
if I ever wanted to *add* more to all the models, then having a parent
model would allow me to do so without having to rejigger the code in
each model.


Paul M. Foster

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to