I’m a newbie to .NET. I have a class called Project, a project can have multiple forecasts.Now If I want to check if the projects has any forecasts or not should I use a readonly boolean property called HasForecast() or should I use a method named HasForecast() which basically returns a boolean value.From framework design guidelines I came to know that methods should be used when the operation is complex,since here I’m retrieving the value of forecasts from DB should I consider method, or since it is a logical data member should I use a property.If I use a property can I call a method in DBLayer from its getter.Please explain
Regards, Ravi
Properties should be very light weight that act and feel like fields. If you needs to access a database then you should use a method.
See MSDN here: http://msdn.microsoft.com/en-us/library/bzwdh01d(VS.71).aspx
Properties vs. Methods
Class library designers often must decide between implementing a class member as a property or a method. In general, methods represent actions and properties represent data. Use the following guidelines to help you choose between these options.
Use a property when
Use a method when: