RBCC Posted February 15, 2004 Posted February 15, 2004 I am trying to learn when I should use a method and when should I use property? I am trying to write a one line routine that multiplies 2 denominators of a fraction together. Should I use a method or property I have a class that has the numerator and denominator in it and I would like to know it is good programming practice to do calculations in a property? JOHN :confused: :confused: :confused: Quote
Moderators Robby Posted February 15, 2004 Moderators Posted February 15, 2004 Use a method for calculations. Think of properties as you would the properties of a button or a textbox. Quote Visit...Bassic Software
RBCC Posted February 15, 2004 Author Posted February 15, 2004 Can you not use a property for a calculation? Quote
RBCC Posted February 15, 2004 Author Posted February 15, 2004 Without being public how do you call a method with the data from a textbox? Quote
Moderators Robby Posted February 15, 2004 Moderators Posted February 15, 2004 You can pass the textbox or its contents to the method as an argument. Quote Visit...Bassic Software
Heiko Posted February 15, 2004 Posted February 15, 2004 IMHO, someone who sets a property value would not expect any side effects. If side effects are going to occur, use a method. Quote .nerd
*Experts* Bucky Posted February 15, 2004 *Experts* Posted February 15, 2004 A "side effect" would be changing the value that the user passed into a function without them expecting it, which is not usually done in a property accessor. Like Robby said, functions should be used to change and return values. For example, it's more advisable to have a Disconnect() method than to have the user set the Connected property to false. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
RBCC Posted February 16, 2004 Author Posted February 16, 2004 So if had to calculate and output a common denominator in a textbox. ie: Switch the value to the common denominator calcultion I should use a property? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.