Jump to content


Photo

**SOLVED** how can I extend multiple classes?


  • Please log in to reply
4 replies to this topic

#1 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 07 September 2006 - 06:56 PM

Any advice?

thanks!
...drkstr

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 September 2006 - 07:08 PM

can you be more specific? if you're looking to have one class that extends multiple ones, it ain't gonna happen. however, if you're wanting to simply extend multiple levels, you can just continue lik this:
<?php
class Organism {
  var $distinction;
  
  function Organism($distinction) {
    $this->distinction = $distinction;
  }
}

class Person extends Organism {
  function Person() {
    parent::Organism("Human");
  }
}

class User extends Person {
  var $username;

  function User($username) {
    parent::Person();
    $this->username = $username;
  }
}
?>

at least, i think i got all my references correct :P ... coding on the fly lends itself to errors!

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 07 September 2006 - 08:22 PM

Darn, I guess it's not going to happen then. I have a data template and a service template and I wanted to extend them both into an actual "library" object which is customized for it's actual use. I'm going to have a *lot* of these objects, so I was trying to get around rewriting the same code over and over. I gues I will just extend the service template and make an isntance of the data object in the child. The data template doesn't have that much code, and the only thing that will change in the service template is the name of the class, so I guess it would make sence to just get rid of the data template and just duplicate the code in each of the data objects.

Thanks for the quick reply!
...drkstr

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 September 2006 - 08:29 PM

so... why not create a third class that has member variables that are actually instances of the first two objects? then, you could write member functions that would access given portions of either of the other two classes and act as though you had joined the classes into one.

make sense?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 08 September 2006 - 01:26 AM

Ahh, That's a great idea!

I'll just change the protected data/methods to public, and I'll be good to go.

Thanks for the help!
...drkstr




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users