Re: Insult my code!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

> 2009/10/7 Paul M Foster <paulf@xxxxxxxxxxxxxxxxx>:
> 
> > 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

parent::Model();

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

-- 
Paul M. Foster

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux