Re: PHP class question

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

 



Peter van der Does wrote:
I have the following situation.

I wrote some software and split it up into functionality:

class core {
  function go{
  }
}

class A extends core {
  // PHP4 constructor
  function A {
    $this->go();
  }

}

class B extends core {
}

In core I define functions and variables that are to be used
through out my program and to address those functions/variables I just
use $this-> .

Now I ran into a situation where class A needs to be extended with
another class. This is not my choice, it's part of a framework I have
to use.

Currently I solved this by doing this:

class A extends framework_class {
  $var core;

  // PHP4 constructor
  function A {
    $this->core = new core();
    $this->core->go();
  }
}

The question I have, is this a good solution, is it the only solution
or are there different ways to tackle this?
As you might see it needs to run in PHP4.


has to extend? if it *has* to extend then you have no choice, but you may want to look up on class inheritance, specifically inheritance vs composition.

also the "isa" / "hasa" rule /should/ always apply.

which one of the following is true
1: A isa framework_class_name
2: A hasa framework_class_name

if it's 1 then you extend
if it's 2 then A should contain an instance of framework_class

eg:
class A
{
  var $framework_class = new framework_class_name();
}

you can also always proxy the methods you need.

all in, this appears to be a design pattern issue and really can't help any more unless you give some specifics. (like the source of your classes and the framework class you need to extend)

regards,

nathan

incidentally, I play inheritance vs composition as game with my 4 year old son, and he's really good - the untainted mind of a child can easily solve things us older types find more complex.
eg: car isa wheel, car hasa wheel

--
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