3

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 manage 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.

Community
  • 1
  • 1
sunwukung
  • 2,815
  • 3
  • 41
  • 56
  • 1
    *(related)* [Dependency Inversion and the Separated Interface Pattern](http://www.aspiringcraftsman.com/tag/dependency-inversion-principle/) – Gordon Jun 14 '10 at 21:55
  • 1
    *(related)* [Framework Design Guidelines: Data Source Architectural Patterns](http://www.informit.com/articles/article.aspx?p=1398618&seqNum=4) – Gordon Jun 14 '10 at 22:09

2 Answers2

0

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() {
        //...
    }
}
TheLQ
  • 14,830
  • 14
  • 69
  • 107
  • I think the OP does not want to know whether interfaces are possible at all, but asked for an example on the *Separated Interface* pattern, as given at http://martinfowler.com/eaaCatalog/separatedInterface.html – Gordon Jun 14 '10 at 21:43
  • Thank you Gordon. This was not the droid I was looking for Lord Quackstar (;) – sunwukung Jun 15 '10 at 07:30
0

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

wimvds
  • 12,790
  • 2
  • 41
  • 42
  • 2 reasons: 1 - information on the pattern is hard to find. 2 - the UML for the pattern omits a crucial detail - the dependency on an external configuration file. – sunwukung Jun 15 '10 at 13:37