[nycphp-talk] Constants interfaces
Kenneth Dombrowski
kenneth at ylayali.net
Wed Sep 3 16:23:22 EDT 2008
On 08-09-03 15:12 -0400, Michael B Allen wrote:
> On Wed, Sep 3, 2008 at 2:20 PM, Kenneth Dombrowski <kenneth at ylayali.net> wrote:
> > I don't have a problem with multiple inheritence, it just seems very
> > kludgey to me to implement it with interfaces; I guesss PHP gives you
> > little choice though..
>
> Quite the opposite. The only non-kludgey way to implement multiple
> inheritance is to use interfaces because if you use a class you cannot
> implement *it* without extending it
As far as I can tell, it is the only kludgey or non-kludgey way to
implement multiple inheritance in PHP, and all you can inherit from an
Interface is consts.
> and you cannot (or should not)
> extend multiple classes as overriding inherited methods can easily
> lead to non-deterministic behavior.
It's quite idiomatic in other languages to extend multiple base classes.
> For example, let's say you have financial instrument interfaces
> "Stock", "Bond", "MutualFund" and "MoneyMarket" where a mutual fund
> can be traded like a stock or a bond but a money market instrument has
> characteristics of a mutual fund (I'm not a financial wiz - this is
> just an example). So which one do you make the base class? The answer
> is very simple: none. You make an interface for all of them and then
> create concrete classes that implement each of the interfaces
> required.
That's what an Abstract class is for. An interface is for exposing a
contractual set of methods, like Observer, Observeable, etc..
More information about the talk
mailing list