> 3. Your class does not depend on any data members, so why not make the
> methods static? That way they can be called without having to instantiate
> the class. This saves system resources.
>> 3. Your class does not depend on any data members, so why not make
>> the methods static? That way they can be called without having to
[quoted text clipped - 12 lines]
>
> -- chris
Well I was just commenting on the class as it was, which didn't use any
data members. In general, static methods require only one copy in memory,
so it's more cost effective. But, in this case the code was creating Lists
within the methods, and re-doing that every time it was needed would again
increase the cost.
From a pure OO standpoint you may be right, but on the other hand static
members and methods are available, so why not use them?
Like I said in my first sentence in reply to the OP, it all depends on what
you need. If you never need to search the same directories or search for
the same files, static might be better (although with the code as it is,
I'm not really convinced of that, I'm talking about general concepts here).
If you have to search the same trees over and over, keeping them in memory
is obviously better.
Oliver Wong - 16 Nov 2005 20:23 GMT
> In general, static methods require only one copy in memory,
> so it's more cost effective.
I believe that there's only ever one copy of methods in memory anyway,
whether they are static or not. That is, even if a method is non-static, the
code for that method does not change from one instance of an given class
from the next, so you only need to store that method in memory once, and
every instance can have a reference to that same memory location.
The nice thing about static methods is that you don't need an instance
of a class to invoke its static methods.
- Oliver
Chris Uppal - 17 Nov 2005 08:31 GMT
> In general, static methods require only one copy in memory,
> so it's more cost effective.
Static methods are no more expensive than non-static. There is only one copy
of each.
> From a pure OO standpoint you may be right, but on the other hand static
> members and methods are available, so why not use them?
<shrug/> Why make it hard for yourself ?
I suspect that the criticism of the OP's first effort was (at least in part)
because s/he had just written completely non-OO code and wrapped a "class"
around it. Had s/he not done that then there would have been no reason (not
even a bad reason like not wanting to pass an extra argument around everywhere)
not to filter the list of files as it was created instead of building the whole
list, /then/ filtering.
-- chris