Hi:

I added the proposal to the RFC.
See 
http://wiki.php.net/rfc/horizontalreuse#requiring_composing_class_to_implement_interface

===== Requiring Composing Class to Implement Interface =====

Traits are able to express required methods by using abstract method 
declarations.
An abstract method can be satisfied in varios ways, for instance by 
implementing it
in the composing class or by bringing it in from another Trait.

However, for traits that require complex interfaces to be satisfied, this 
approach is tedious
and fragile, since it requires the developer to state all used methods 
explicitly.

Another solution is that a Trait expresses a requirement for the composing 
class to implement
a certain interface. This is not entirely identical to using abstract methods, 
however.
First, it imposes a requirement on interface level and thus will have the same 
fragility
with respect to interface changes as all other clients of an interface.
On the other hand, it avoids duplications of abstract method definitions and 
makes
the interface the main entity of responsibility as for normal client-interface 
uses
in current code.

<?php
// IteratorUser works with $this using the Iterator interface
trait IteratorUser require Iterator {
    function foo() {
        $next = $this->next();
        ...
    }
}

// composed into a class that needs to implement the interface
class Example implements Iterator {
  use IteratorUser;
}

Are there any objections to implementing this?

Thanks
Stefan


-- 
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax:   +32 2 629 3525


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

Reply via email to