抽象界面模式

发布于 2025-01-05 00:06:57 字数 113 浏览 1 评论 0原文

任何人都可以提供抽象接口模式的解释吗?

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

Can any one provide explanation of Abstract interface pattern.

The book "N-Layered Domain-Oriented Architecture Guide with .NET 4.0" has reference of this pattern, but no explanation.

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

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

发布评论

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

评论(2

浪菊怪哟 2025-01-12 00:06:57

我认为这意味着拥有一个接口、一个实现该接口的抽象类,然后是几个从该抽象类继承的非抽象类。在 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
}

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

I believe it means having an interface, an abstract class that implements that interface and then several non-abstract classes that inherit from the abstract class. In C# code:

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
}

The advantage of using this pattern is that it combines benefits of interfaces (flexibility) with benefits of abstract base classes (sharing implementation).

飘落散花 2025-01-12 00:06:57

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

在 C# 中,我们有“interface”关键字,它的作用完全相同。

Abstract Interface doesn't really exist in C#. In C++ you have the notion of a "pure abstract" class, in which all methods are abstract, hence it's an abstract class that only defines an interface.

In C# we have the 'interface' keyword instead, which does the exact same thing.

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