Jan 29, 2008

Property vs Method

  • If a property accessor has abserable side effects, implment a method instead of a property.
  • If the implementation of a property is considerably more expensive than that of a field, implementation a method instead. When you expose a property, you suggest to users that making frequent calls to it is acceptable. When you implement a method, you suggest to users that they save an reuse a returned value if they repeately need it.
  • If some properties require a user to set them in a predefined order, implement those properties as methods. In general, you should design your components so that properties can be set in any order.
  • If you need a write-only property, implement a method instead.