What about something like this?
(actual code not tested, but concept has...)

class FOO
{
  function Fred() { echo "Fred in FOO"; }
}

class BAR
{
  function Fred() { echo "Fred in BAR"; }
}

class BAZ
{
  var $subclass;

  function BAZ($num)
  {
    if ($num == 1)  $this->subclass = new FOO();
    if ($num == 2)  $this->subclass = new BAR();
  }

  function Fred() { $this->subclass->Fred(); }
}


-----Original Message-----
From: jsWalter [mailto:[EMAIL PROTECTED]
Sent: Thursday, 25 September 2003 4:30 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Q on Class, inhertance, ec... (a bit long)


I have a quandary and I hope I can explain myself well enough that someone
may understand and enlighten me.
I am in the middle of building a (largish) Class. It is done for the most
part, at least all pieces are there. Now I'm just trying to put the pieces
together in a logical order.

This is my issue; I have 2 sets of 12 methods that are identical in nature,
but differ in implementation. Sort of like DB and Auth can handle different
databases. (And yes, I've been studying them, but still am at a loss)

I have my main class, BAZ, then I have 2 sub Classes, BAR and FOO.

If x = 1, then I want to load BAR and utilize these 12 methods that are
defined there.

If x =2, then I want to load FOO and utilize these 12 methods that are
defined there.

The methods in each Sub-Class have the same names.

My question is, how do I "wrap" this so that my methods calls are ignorant
of with sub-class is used?

Example: $myObject = new BAZ ( x = 2 ); // Utilize methods in FOO

$myFred = $myObject->Fred;

$myBarney = $myObject->Barney;

or

$myObject = new BAZ ( x = 1 ); // Utilize methods in BAR

$myFred = $myObject->Fred;

$myBarney = $myObject->Barney;

And to throw a monkey with this wrenth, the 'factory' of the main class
needs access to a few of these 'common' methods as well to prep several
properties.

Each sub-class contains about 600 lines of code, that I would rather not
have in a single class file.

Also, do I have to have these 12 methods names defined, but empty, in the
main class?

I hope this explains my non-understanding of PHP OOP to the level that
someone can point me in the right direction.

Thanks for your help.

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

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

Reply via email to