PHP 可以实现分离接口吗?

发布于 2024-09-05 15:30:14 字数 322 浏览 3 评论 0原文

我最近问了一个关于工作单元和数据映射器类之间依赖关系解析的问题:依赖注入和工作单元模式 - (Gabor de Mooij 回答 - 谢谢)

在 PoEAA 中,Martin Fowler 建议使用分离接口 来管理这些依赖项。我的问题很简单 - 实际上是否可以在 PHP 中实现此模式,或者它是否特定于 Java 接口?我到处搜索,很难在 PoEAA 之外的任何地方找到这种模式的参考。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放血 2024-09-12 15:30:14

是的,这是可能的(你为什么怀疑这一点?)。如果您正在寻找示例,可以查看 Cookie 模式博客< /a>.

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

2024-09-12 15:30:14

你试过谷歌吗?第一个结果:

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

这本质上是说使用一个像接口一样的抽象类。

向下滚动一点,它表明你可以做到这一点

interface Exportable {
    public function export();
}

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

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

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() {
        //...
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文