What guidelines are suitable for determining when to apply a member of a class as a property compared to a method?

. Sub PDF's NET PDF encoding standards , which began to appear in the Sponsored area, appear to indicate that the properties are only suitable for logical data elements (see pages 34–35 of the document). Methods are considered suitable in the following cases:

  • An operation is a transformation, such as Object.ToString ().
  • The operation is expensive enough that you want to tell the user that they should consider caching the result.
  • Retrieving a property value using get accessor will have an observed side effect.
  • Calling a member twice in a row gives different results.
  • The order of execution is important.
  • The element is static, but returns a value that can be changed.
  • The element returns an array.

Most developers agree with the argument of properties and methods above? If so, why? If not, why not?

+5
source share
5 answers

They seem audible and mostly in accordance with the guidelines for developing MSDN elements:

http://msdn.microsoft.com/en-us/library/ms229059.aspx

One point that people sometimes forget (*) is that callers should be able to set properties in any order. It is especially important for classes that support designers, because you cannot be sure that the generated code will set properties.

(*) , Ajax Control Toolkit Codeplex - , .

" , ", , DateTime.Now.

+3

, . , " , ". , , - , .

, Object Orientation - , , ; , .

+1

.

, "", - "". , , , "" .

, , , .

0

, , , . .

0

, , , , .

"get", FxCop. GetPeopleList() , FxCop , .

0

All Articles