Re: [PHP] Multiple Inheritance Concern

2009-12-26 Thread Daniel Kolbo
Larry Garfield wrote:
> On Friday 25 December 2009 8:02:06 pm Daniel Kolbo wrote:
>> Hello PHPers,
>>
>> I've learned that php doesn't support multiple inheritance, b/c if you
>> need multiple inheritance usually it is a sign you've got a design
>> imperfection...or so they say.
>>
>> Well, I'm using a framework (Codeigniter), and i'm extending the core
>> libraries.  The trouble is, I want to also extend a second custom class,
>> and I don't want to change the core codeigniter class definitions as
>> this makes for awkward upgrades.
>>
>> I read about mixins - no thank you.  i do not want to even think about
>> mixins as it looks like it would be the source of all debug hell...
>>
>> What's a programmer to do?  Is the only option i am really left with to
>> duplicate the code in each class?
>>
>> Thanks,
>> dK
>> `
> 
> If the original author of one or both libraries did their job right, they'll 
> have provided an interface as well as the class that implements it.  Then you 
> can implement the interface and pass through to a new instance using 
> composition.
> 
> To wit:
> 
> interface AInterface {
>   public function doA();
> }
> 
> interface BInterface {
>   public function doB();
> }
> 
> class A implements AInterface {
>   public function doA() { ... }
> }
> 
> class B implements BInterface {
>   public function doB() { ... }
> }
> 
> class YourClass extends A implements BInterface {
> 
>   protected $b;
> 
>   public function __construct() {
> $this->b = new B();
>   }
> 
>   public function doB() {
> return $this->b->doB();
>   }
> }
> 
> (It would probably be a little more complicated in a real use case, but 
> hopefully that should get you the idea.)
> 
> Mind you, that presumes that the code you're dealing with provides interfaces 
> and when doing type checking checks against the interfaces rather than the 
> classes themselves.  If they don't, you should file a bug against that base 
> library as They're Doing It Wrong(tm).
> 

Yes, I understand.  Thanks for taking the time to write up the example.

Thanks,
dK
`

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



Re: [PHP] Multiple Inheritance Concern

2009-12-25 Thread Larry Garfield
On Friday 25 December 2009 8:02:06 pm Daniel Kolbo wrote:
> Hello PHPers,
>
> I've learned that php doesn't support multiple inheritance, b/c if you
> need multiple inheritance usually it is a sign you've got a design
> imperfection...or so they say.
>
> Well, I'm using a framework (Codeigniter), and i'm extending the core
> libraries.  The trouble is, I want to also extend a second custom class,
> and I don't want to change the core codeigniter class definitions as
> this makes for awkward upgrades.
>
> I read about mixins - no thank you.  i do not want to even think about
> mixins as it looks like it would be the source of all debug hell...
>
> What's a programmer to do?  Is the only option i am really left with to
> duplicate the code in each class?
>
> Thanks,
> dK
> `

If the original author of one or both libraries did their job right, they'll 
have provided an interface as well as the class that implements it.  Then you 
can implement the interface and pass through to a new instance using 
composition.

To wit:

interface AInterface {
  public function doA();
}

interface BInterface {
  public function doB();
}

class A implements AInterface {
  public function doA() { ... }
}

class B implements BInterface {
  public function doB() { ... }
}

class YourClass extends A implements BInterface {

  protected $b;

  public function __construct() {
$this->b = new B();
  }

  public function doB() {
return $this->b->doB();
  }
}

(It would probably be a little more complicated in a real use case, but 
hopefully that should get you the idea.)

Mind you, that presumes that the code you're dealing with provides interfaces 
and when doing type checking checks against the interfaces rather than the 
classes themselves.  If they don't, you should file a bug against that base 
library as They're Doing It Wrong(tm).

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Multiple Inheritance Concern

2009-12-25 Thread Daniel Kolbo
Daniel Kolbo wrote:
> Hello PHPers,
> 
> I've learned that php doesn't support multiple inheritance, b/c if you
> need multiple inheritance usually it is a sign you've got a design
> imperfection...or so they say.
> 
> Well, I'm using a framework (Codeigniter), and i'm extending the core
> libraries.  The trouble is, I want to also extend a second custom class,
> and I don't want to change the core codeigniter class definitions as
> this makes for awkward upgrades.
> 
> I read about mixins - no thank you.  i do not want to even think about
> mixins as it looks like it would be the source of all debug hell...
> 
> What's a programmer to do?  Is the only option i am really left with to
> duplicate the code in each class?
> 
> Thanks,
> dK
> `

I just found this in the archive:
http://old.nabble.com/Multiple-Inheritance-td15717829.html

That example Nathan provides of mixin is a lot cleaner than a different
example (from a different poster on a different site) i was looking at.
 I could probably use the method Nathan proposed in a pretty clean way.

i'm justified for using this multiple inheritance workaround to keep the
core framework untouched?

Does anyone else have a different approach or suggestion?

Thanks,
dK
`

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



[PHP] Multiple Inheritance Concern

2009-12-25 Thread Daniel Kolbo
Hello PHPers,

I've learned that php doesn't support multiple inheritance, b/c if you
need multiple inheritance usually it is a sign you've got a design
imperfection...or so they say.

Well, I'm using a framework (Codeigniter), and i'm extending the core
libraries.  The trouble is, I want to also extend a second custom class,
and I don't want to change the core codeigniter class definitions as
this makes for awkward upgrades.

I read about mixins - no thank you.  i do not want to even think about
mixins as it looks like it would be the source of all debug hell...

What's a programmer to do?  Is the only option i am really left with to
duplicate the code in each class?

Thanks,
dK
`

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