使用"基地"不好的做法,即使它可能是很好的可读性? [英] Is using "base" bad practice even though it might be good for readability?

查看:112
本文介绍了使用"基地"不好的做法,即使它可能是很好的可读性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个主观的问题,但我总是好奇的编码风格最佳实践。 ReSharper的4.5是给我的关键字基地警告之前基方法的实现类,来电即

I know this is a subjective question, but I'm always curious about best-practices in coding style. ReSharper 4.5 is giving me a warning for the keyword "base" before base method calls in implementation classes, i.e.,

base.DoCommonBaseBehaviorThing();

尽管我很欣赏的少就是好的心态,我也花了很多时间的调试/保持高度链应用程序,并且觉得它可能有助于知道,成员调用是一个基本对象只是看它。这是很简单的改变ReSharper的的规则,当然,但是你们怎么想?如果基地呼叫基地成员时,可以使用?

While I appreciate the "less is better" mentality, I also have spent a lot of time debugging/maintaining highly-chained applications, and feel like it might help to know that a member call is to a base object just by looking at it. It's simple enough to change ReSharper's rules, of course, but what do y'all think? Should "base" be used when calling base members?

推荐答案

你应该使用基地唯一的一次。 MethodCall(); 是当你有在子类的同名重写的方法,但实际上你想调用父方法

The only time you should use base.MethodCall(); is when you have an overridden method of the same name in the child class, but you actually want to call the method in the parent.

对于所有其他情况下,只需要使用 MethodCall(); 。像这个

For all other cases, just use MethodCall();.

关键词不作代码的可读性,应当避免对所有情况除非的它们是必须的 - 如在我上述情况。

Keywords like this and base do not make the code more readable and should be avoided for all cases unless they are necessary--such as in the case I described above.

这篇关于使用"基地"不好的做法,即使它可能是很好的可读性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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