On May 6, 2008, at 12:21 PM, Lars Strojny wrote:

I think this is too unspecific. At least the visibility, setter and/or
getter and type-hint (assuming we will have type hints) should be
defined. Otherwise defining properties in interfaces become useless as
it does not tell somebody more except "there is a property".

interface Something
{
    public $property {
        string public function get();
        string protected function set(string $value);
    }
}


Hi Lars,

It isn't necessary to specify the visibility in an interface because all interface members are public.

Specifying the accessor methods in an interface reveals too much of the implementation. Properties (the kind with accessor methods) are themselves an abstract concept. You want to be able to take an interface definition such as:

interface foo {
        public $bar;  // if you prefer this to abstract $foo;
}

and implement it like this:

class DoIt implements foo {
        public $bar;
}

or to implement it using setters, using your notation:

class DoIt2 implements foo {
        public $foo {
                public function get();
                protected function set($value); 
        }
}

The whole point of this kind of property is that the caller is never supposed to know if they are just accessing a object instance variable or an accessor method. This is called the uniform access principle.
http://en.wikipedia.org/wiki/Uniform_access_principle

Here is how C# handles properties in an interface:
http://msdn.microsoft.com/en-us/library/64syzecx.aspx

"The accessor of an interface property does not have a body. Thus, the purpose of the accessors is to indicate whether the property is read- write, read-only, or write-only."

So, yeah, "there is a property named foo" is about all an interface should say.

Best Regards,

Jeff



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to