DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

17
kicks
published 11 months, 18 days ago, submitted by manovich 11 months, 19 days ago

dotnettipoftheday.org — Guidelines for choosing between implementing a class member as a property or a method.

Add a comment 6 comments | category: | Views: 2 | Get KickIt image code
tags: | tag it

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:
"Calling the member twice in succession produces different results."

Not necessarily, DateTime.Now and Random.Next are examples of a valid propertys that produce different results when called in succession.

[)amien
posted by DamienG DamienG 11 months, 18 days ago
Minor correction: System.Random.Next is not a property.

Discussing DateTime.Now is a rather moot, academic exercise as it follows "Use a property when the member is a logical data member" [1] ;)

-- bg

[1] http://msdn2.microsoft.com/en-us/library/bzwdh01d(VS.71).aspx#cpconpropertyusageguidelinesanchor1
posted by boki boki 11 months, 18 days ago
Yeah sorry Random.Next isn't... but Stopwatch.Elapsed is ;-)

Perhaps it should be worded "Calling the member twice in succession produces different results with the exception of time-based activities"

[)amien
posted by DamienG DamienG 11 months, 18 days ago
Biggest one that is missed: The operation may throw an exception. You should never have to wrap property accesses within try/catch blocks.

Biggest one that's complete bullshit: If it returns an array. Why? Because you cannot guarantee callers won't change the state of the array.

1) How is this different than any property that exposes an object via a getter?
2) Have you seen the framework? Collections are regularly exposed via properties.

This "hint" is full of fail and ugly. NO KICK FOR U.
posted by yesthatmcgurk yesthatmcgurk 11 months, 18 days ago
Yeah, I must agree that the arrays one I just ignored thinking Collections get returned in the framework. :)

On the bonus side, there is the link in the article to MS's Design Guidelines for Class Library Developers.
posted by powerrush powerrush 11 months, 18 days ago
Common sense should be used when applying any guidelines. These are guidelines not strict rules.

Regarding returning array: IMHO if by desing it is acceptable that array/collection will be modified by external code, then I think member can be implemented as property (every rule has an exception).
posted by Sirko 11 months, 18 days ago



information Login or create an account to comment on this story
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge