在部分类中实现接口 [英] Implementing interfaces in partial classes

查看:75
本文介绍了在部分类中实现接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个实现许多接口的类,使用partial class定义在单独的文件中实现每个接口是否有意义?

Consider a class which implements a lot of interfaces, would it make sense to implement each interface in a separate file using partial class definitions?

这会滥用语言功能还是我不知道的惯用语?

Would this be an abuse of the language feature or is it an idiom I'm unaware of?

推荐答案

如果您的类必须实现许多接口,则这是管理源代码的一种合理方法,是的.您可以编辑项目文件,以使其中的几个依赖于一个主"类文件,这使解决方案资源管理器更易于使用.

If your class has to implement many interfaces, that's a reasonable way of managing the source, yes. You can edit the project file to make several of them depend on one "main" class file, which makes the Solution Explorer easier to work with.

您应该问自己,是否不应该有几个较小的类,每个类都只实现一个接口.有时这将是一种更好的方法,有时却不是-但始终值得提出这个问题.

You should ask yourself whether you shouldn't have several smaller classes each implementing a single interface though. Sometimes that will be a better approach, sometimes not - but it's always worth asking the question.

这篇关于在部分类中实现接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆