Properties or Methods?

I am writing a .NET application which has a number of classes that are basically just data holders. They are instantiated by Factory objects that know about the DB but they themselves are just a collection of data members. For example, the User object has Email, Name and other such values but does no real work.

I did create all the getter methods (there are no setter methods as all values are put in the constructor) as methods but then I discovered Properties — one of the few things different between C# and Java. I am now in the process or replacing all get methods with Properties. Probably because I’m used to Java though code like this, “user.Region.Currency.Code” seems strange. I suppose its no different to “user.Region().Currency().Code()” but it just looks wrong!

I can’t find anything on the web about when to use properties and when to use methods (they are the same thing really) and the fact that I don’t really use setter methods means I don’t get that much benefit from Properties anyway. But I am using them to be more idiomatic and why not. What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.