接口中的抽象类?

发布于 2024-12-03 12:53:48 字数 530 浏览 0 评论 0原文

我将有几个从抽象基类继承的类。

我想确保每个子类都有一个特定的嵌套类,其实际字段由开发人员决定。

在基类abs 中嵌套一个抽象类。 class 似乎并没有解决这个问题,因为在实际编码过程中,嵌套的 abs.类和子类中的嵌套类都可用(显示在智能感知中)。

让基类实现一个包含类的接口是行不通的,因为接口仅引用可以实现的方法,而不是类(意味着实现接口需要实现方法,但没有提及接口中的类。

有什么想法吗?

<评论中的澄清:

我有三个表,它们有大约 50 个共同字段。

我希望每个表都有一组独特的字段(因为它们确实有不同的业务功能)。但想要有一些与常见相关的共享方法 因此,

这些方法位于基类中,但对于唯一字段,我还希望在基类中包含一个嵌套类。字段,因此需要嵌套的abs类或其他

我希望开发人员将独特的字段分组到一个嵌套类中,因此我们有两组嵌套类:“CommonData”和“UniqueData”。该数字约为 190 个公共字段和最多 10 个唯一字段,因此我正在尝试建立一些分组以使事情更易于使用。

I'm going to have several classes that will inherit from a base abstract class.

I'd like to make sure each of the subclasses has a certain nested class whose actual fields are up to the developer.

Nesting an abstract class inside the base abs. class doesn't seem to do the trick because during actual coding, both the nested abs. class and the nested class in the subclass both are available (show up in intellisense).

Having the base class implement an interface that includes a class doesn't work since interfaces only refer to methods that can be implemented, not classes (meaning implementing the interface requires implements methods, but says nothing about classes in the interface.

Any ideas?

Clarifications from the comments:

I have three tables that have about 50 fields in common. They each also have a set of unique fields.

I want to have one class for each (because they do have different biz functions) but want to have some shared methods relating to the common fields.

So those methods go in the base abs class. I also want a single nested class in the base class for the common fields. For the unique fields though, I want to make sure whoever codes the subclass includes a nested class for the unique fields, hence the need for a nested abs class or whatever

It's the unique fields I want developers to group together into a nested class. So we have two sets of nested classes: "CommonData" and "UniqueData". The number is around 190 common fields and up to 10 unique, so I'm trying to establish some groupings to make things easier to work with.

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

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

发布评论

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

评论(2

不顾 2024-12-10 12:53:48

只需向嵌套类类型的基类(或接口)添加一个属性

Just add a property to the base class (or interface) that is of the nested class's type

鹿童谣 2024-12-10 12:53:48

让基类实现一个包含类的接口是行不通的,因为接口只引用可以实现的方法,而不是类(意味着实现接口需要实现方法,但没有提及接口中的类。< /em>

VB.Net 可以在接口内声明类,但 C# 不能。

Public Interface Foo

    MustInherit Class Bar

    End Class

End Interface

不过,这可能有点太奇特了 - 如果我在某些代码中发现它,我会感到很困惑。

Having the base class implement an interface that includes a class doesn't work since interfaces only refer to methods that can be implemented, not classes (meaning implementing the interface requires implements methods, but says nothing about classes in the interface.

VB.Net can have classes declared inside interfaces, C# can't.

Public Interface Foo

    MustInherit Class Bar

    End Class

End Interface

It might be a bit too exotic though - it would confuse the heck out of me if I found it in some code.

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