|
-
Mar 30th, 2004, 10:31 AM
#1
Thread Starter
Frenzied Member
method or function?
need some opinions: Let's say you have an object that you want to use over and over. you could either create an internal method to reset the class's fields back to defaults or you can create a function to do the same (property = nothing). what is considered the best practice?
before I get flamed LOL, my boss wanted me to use the same objects over and over. is there a draw-back to this?
-
Mar 30th, 2004, 10:49 AM
#2
You have three choices:
1) A method - can take paremeters, but cannot return sucess/failure
2) A function - also can take parameters, AND can return if it was successful or not
3) A property - no parameters, no return value
The choice is really yours and what you need to do. Do you need to pass in parameters? Then a method or function is needed. Do you care about a return value? Then use the function. If you don't need either, then a property will work.
TG
-
Mar 30th, 2004, 03:07 PM
#3
Frenzied Member
I tend to use a lot of boolean functions, just for the reason techgnome stated. Let's the calling function know if it succeeded. You could, I think, throw an exception to be caught in the calling function instead, we used to do that in C++ class.
-
Mar 31st, 2004, 10:37 AM
#4
I would opt for a method. In general - a property is used to define the current state of an object, whereas a method manipulates in some way the data inside the object.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|