接口不应该有属性? [英] Interface should not have properties?

查看:171
本文介绍了接口不应该有属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的办公室的同事告诉我今天这是不好的做法,在接口的使用性能。他红,在某些MSDN文章(S),而我找不到(好,我是想在谷歌几次,大概跟错了键字)。他还告诉我,只有方法应该是在界面。 现在,我知道这是不严格的规则,因为很明显在.net中,你可以做财产签名接口和编译。

My office colleague told me today that is bad practice to use properties in interfaces. He red that in some MSDN article(s), which I couldn't find (well I was trying few times on google, probably with wrong key words). He also told me that only methods should be in interface. Now, I am aware that is is not strict rule, since obviously in .net you can make property signature in interface and compile it.

不过,这是真的是一个坏的实践/设计/ OOP?为什么?

But is this true to be a bad practice/design/oop? And why?

他指出,以正确的文学或网络资源将是有益的了。

Pointing out to right literature or web resource would be helpful too.

感谢

推荐答案

我就加我的声音在这里也 - 我从来没有碰到过这样的建议。属性是有效的一对get / set方法。

I'll just add my voice in here as well - I've never come across this recommendation. A property is effectively a pair of get/set methods.

像其他的设计决策。如果genuintely是有道理的;如果是适当的下设计的系统中,如果它不会引起维护问题,如果它不导致性能问题,应该没有理由不能做到这一点。

Like every other design decision. If it genuintely makes sense; if it is appropriate for the system under design, if it doesn't cause maintenance problems, if it doesn't cause performance problems, there should be no reason you can't do it.

这篇关于接口不应该有属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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