开发者

Is it possible to implement Separated Interface in PHP?

I recently asked a question regarding the resolution of dependencies between Unit of Work and Data Mapper classes: Dependency Injection and Unit of Work pattern - (which was answered by Gabor de Mooij - thx)

In PoEAA, Martin Fowler suggests using Separated Interface to ma开发者_StackOverflow中文版nage these dependencies. My question is simple - is it actually possible to implement this pattern in PHP, or is it specific to Java interfaces? I've searched high and low and it's hard to find references to this pattern anywhere outside of PoEAA.


Yes, it is possible (why would you doubt that?). If you're looking for an example, you could check out the Cookie Pattern blog.


Have you tried Google? First result:

http://www.ibm.com/developerworks/opensource/library/os-advphpobj/#N101E7

This essentially says to use an abstract class that acts like an interface.

Scrolling down a bit, it shows that you can do it interfaces

interface Exportable {
    public function export();
}

class OurNews extends ThirdPartyNews 
              implements Exportable {
    // ...
    function export() {
        print "OurNews export\n";
    }
}

class Dictionary implements Exportable, Iterator {
    function export() {
        //...
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜