English 中文(简体)
“货物不应包括大量的逻辑”。 真实或虚假?
原标题:"Getters should not include large amounts of logic." True or false?

我倾向于认为,接收器在另外一套关于返还价值(或一套价值)的轻度指示上,只不过是使用控制包裹。

因此,当我发现自己撰写的时间更长,而且更多的公民党-宗教组织,我感到。 也许这并不是test鱼运动。 在我自己的法典中打一个跳板(特别是如果在方法与接听器电话之间有明显差异时,请参阅C#),那么我就默认这些是轻重——事实上情况可能并非如此。

有什么共识? 利用其他人的图书馆,请上write/strong> 重型 get子 或者,你是否倾向于将重型接收器视为“完整方法”?

PS。 由于语言差异,我预计在这方面会有一些不同的想法。

最佳回答

确实。 购物人应当获得一个简单的成员,或者应当对衍生价值进行计算和加固,然后回去附价(在未加固的电离层中,应当仅仅收回这一价值)。 如果我有做大量计算的职能,那么我就将其命名为computeX,而不是getX

问题回答

财产领取人打算收回价值。 因此,当开发商叫他们时,人们期望这一呼吁能够立即(几乎)以价值回报。 如果无法满足这一期望,最好是使用一种方法而不是一种财产。

http://msdn.microsoft.com/en-us/library/bzwdh01d.aspx”rel=“noretinger”> 从MSDN:

<>Property Usage Guidelines

Use a method when:
[...]

  • The operation is expensive enough that you want to communicate to the user that they should consider caching the result.the result.

并且:

www.un.org/Depts/DGACM/index_spanish.htm 选择财产方法与

Do use a method, rather than a property, in the following situations.

  • The operation is orders of magnitude slower than a field set would be. If you are even considering providing an asynchronous version of an operation to avoid blocking the thread, it is very likely that the operation is too expensive to be a property. In particular, operations that access the network or the file system (other than once for initialization) should most likely be methods, not properties.

从时间来看,我的方法很少是如此昂贵的,因为时间上是依据托马斯所公布的准则。 但是,一般说来,要求获得者不应影响那类人的状况。 我没有问题写出一个按要求实际进行计算的老板。

一般而言,我写的是短、高效的字。 但是,你可能会有复杂的问题——需要考虑如何利用电梯。 如果是外部的APIC,那么你对如何使用它没有任何控制,那么就是为了提高效率。

我同意这一点。 比如,根据“OfBirth”对年龄等情况进行计算是有益的。 但我想避免复杂的逻辑,即只需要一个数据库来计算物体财产的价值。 在这种情况下使用方法。

My opinion is that getter should be lightweight, but again as you say there is a broad definition of "lightweight", adding a logger is fine for tracing purpose, and probably some cache logic too and database/web service retrieval .. ouch. your getter is already considered heavy. Getter are syntaxic sugar like setters, I consider that method are more flexible because of the simplicity of using them asynchronously.

But there is no expectation set for your getter performance (maybe try to mention it in the cough documentation ), as it could be trying to retrieve fresh values from slow source. Others are certainly considering getter for simple objects, but as your object could be a proxy for your backend object, I really see not point too set performance expectations as it helps you makes the code more readable and more maintainable.

因此,我的回答是,“取决于”主要取决于贵国物体的抽象程度(低水平物体的简短逻辑,因为其价值可能应当根据固定水平、高水平的长期水平计算)。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...