【问题标题】:Abstract interface pattern抽象接口模式
【发布时间】:2012-02-12 03:29:23
【问题描述】:

谁能提供抽象接口模式的解释。

《N-Layered Domain-Oriented Architecture Guide with .NET 4.0》一书提到了这种模式,但没有解释。

【问题讨论】:

    标签: .net design-patterns architecture domain-driven-design


    【解决方案1】:

    我相信这意味着拥有一个接口,一个实现该接口的抽象类,然后是几个从抽象类继承的非抽象类。在 C# 代码中:

    interface IFoo
    {
        // interface members
    }
    
    abstract class FooBase : IFoo
    {
        // implementation of IFoo and potentially some helper methods
        // some methods can be abstract, some virtual
    }
    
    class ConcreteFoo : FooBase
    {
        // overrides abstract members of FooBase and potentially some virtual ones
    }
    

    使用这种模式的优点是它结合了接口的好处(灵活性)和抽象基类的好处(共享实现)。

    【讨论】:

    【解决方案2】:

    抽象接口在 C# 中并不存在。在 C++ 中,您有“纯抽象”类的概念,其中所有方法都是抽象的,因此它是一个只定义接口的抽象类。

    在 C# 中,我们使用了 'interface' 关键字,它的作用完全相同。

    【讨论】:

    • 我问的是架构模式而不是语言概念。
    • 是的,我回答说它是一个没有任何实现的抽象类。
    猜你喜欢
    • 1970-01-01
    • 2018-08-12
    • 2011-05-22
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多