NYCPHP Meetup

NYPHP.org

[nycphp-talk] Constants interfaces

Michael B Allen ioplex at gmail.com
Wed Sep 3 13:04:00 EDT 2008


On Wed, Sep 3, 2008 at 9:41 AM, Kenneth Dombrowski <kenneth at ylayali.net> wrote:
> Hi Michael,
>
> I have to disagree.
>
> On 08-09-03 02:07 -0400, Michael B Allen wrote:
>>
>> Consider the following:
>>
>>   interface Math_Constants {
>>
>>       const PI = 3.14159265;
>
> No, that's not at all what an interface is for.  An interface is nothing
> more than a contract which specifies what methods its implementors must
> define, it is not a sneaky way to implement multiple inheritance

Well I don't want to get into a big argument about it but I don't agree.

In the abstract sense of the word, an interface defines how to
interact with a separable component of a library. In C this would be a
simple header file containing DEFINEs and prototypes. I the case of an
object oriented library, this would be a class or more generally an
interface definition.

Also, I think interfaces can be used to implement multiple inheritance
(provided that multiple inheritance is warranted or course). There's
nothing wrong with multiple inheritance provided that the concepts
being implemented are orthogonal. In fact, for practical programming
reasons, you have to use multiple interfaces to implement multiple
inheritance (as opposed to extending one class an using interfaces for
the other concepts).

>> I think PI would qualify as part of an interface definition. The value
>> of PI will never change.
>
> If it will never change, there is no value in including it as part of an
> interface definition

I disagree.

For example, a library that provides an interface for a concept like a
circle might very well need a constant like Shape_Circle::PI for the
library to be able to compute things with adequate precision.

And again, an enum defines a type that is restricted to a specific
subset of values. IMO that is unquestionably something that could be
part of an interface definition and in PHP that amounts to a sequence
of const declarations as PHP does not support enums.

Mike

-- 
Michael B Allen
PHP Active Directory SPNEGO SSO
http://www.ioplex.com/



More information about the talk mailing list