C# 接口返回类型
我有几个界面:IOrganizations 和 IPeople。
如果我想返回与某个组织相关的人员列表,我应该在哪个界面中创建它?
结果基于组织,但我返回人员列表
I have a couple of interfaces, IOrganisations and IPeople.
If I want to return a list of people associated with an organisation, which interface do I create this in?
The results are based on an organisation, yet I'm returning a list of people
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在
IOrganization
上执行此操作(并使用IPeople
作为返回类型)。类似这样:
这是因为组织的人员是组织的财产,而不是人民的财产。
Do it on
IOrganisation
(and haveIPeople
as the return type).Something like this:
This is because the people of an organisation is a property of the organisation, not of the people.
听起来它应该在
IOrganization
上 - 毕竟,这就是您将调用它的地方。您拥有的是组织,您想要人员列表 - 您无法从人员列表开始,因此它 >必须是IOrganization
接口的一部分。我发现以复数接口名称开头很奇怪 - 我希望为单个组织使用
IOrganization
,为单个人使用IPerson
。That sounds like it should be on
IOrganization
- that's what you'll call it on, after all. What you have is the organization, you want the list of people - you can't start fromt the list of people, so it must be part of theIOrganization
interface.I find it strange to have plural interface names to start with - I'd expect
IOrganization
for a single organization, andIPerson
for a single person.首先,您可能不应该有复数的接口名称。因此,将它们称为 IOrganization 和 IPerson,然后在您的 IOrganization 界面上,您可能有一个名为的方法:
First of all, your should probably not have pluralized interface names. So call them IOrganization and IPerson and then on your
IOrganisation
interface you might have a method called:哪个属于哪个?
在我看来,
iOrganization.People
将是属于该组织的人员列表(您的“IPeople”界面是代表人员列表还是单个人?)。同样,您可能有一个IPeople.Organizations
,其中列出了一个人所属的所有组织。两者可能都有不同的底层机制 - 也许调用相同的查找表 - 这对于调用代码的人来说并不重要。Which belongs to which?
It seems to me that
iOrganisation.People
would be a list of people ( is your "IPeople" interface representing a list of people or a single person? ) belonging to the organisation. Likewise you might have anIPeople.Organisations
that lists all organisations that a person belongs to. Both will probably have a different underlying mechanism - maybe calling the same lookup table - it doesn't matter to the person calling the code.如果您将组织视为包含人员的集合,那么将其放入
IOrganization
中是很直观的。它看起来像这样:If you think of an organization as a collection containing people, then it's intuitive to put that in
IOrganization
. It would look like this: