-
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?
-
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
-
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.
-
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.