From: Erik V. <eri...@hc...> - 2005-04-26 20:13:03
|
> Erik Vos wrote: > > I'm from a school of thought that classes should be self-managing, > > which is why I tend to include static arrays and methods to manage > > the instances of a class inside that class, as I have done > in Player. > > It's not exactly clear to me what you mean by self-managing. A class that keeps a list of its own instances, and provides methods to find these instances. In some cases it might also instantiate them. > Part of my coding philosophy is that, when taking any action > that needs > to be cleaned up afterward (opening a file, allocating heap > memory, etc.), > that action should be represented by a class object with a > destructor that > cleans it up when it goes out of scope. That way you can't forget it. Cleanup is automatic in Java, if you remember not to keep references to no-longer-needed objects. > But if you mean you want to have a class keep a list of all > objects of that > class, that's easy enough to do without static arrays. <snip> Nice, but what is the advantage above a static array? Looks a lot easier to me. I'm getting the impression that 'static' is synonymous to 'not done' here.... Erik. |