From: Erik V. <eri...@hc...> - 2005-04-26 18:31:09
|
> Over the last few days, I've been working on getting the > initial game options working. If you check out the files in > CVS and run the main() method in test/GameTest.java you'll > see the current state of things. > > However, it looks like the Player class needs some clean-up > work done to it before I go too much further. > > Currently, there are methods that presume the Player is a > collection for housing all players' data and there are > methods that presume the Player is a singular object. > > I think we need to pick one of these styles rather than > cluttering up the class with the ability to work both ways. > > In my opinion, it's very easy to use existing collections to > store multiple singular Player objects (ex: Player[] > allPlayers). This allows the Player class to focus on housing > all the data specific to a single player and makes a bit more > logical sense when we have Player extending CashHolder. > > > Thoughts? Yes. 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. About the Player[] allPlayers (I tend to use ArrayLists because these do not need to be pre-dimensioned): sure, but my point is: where do we store such an array? I have put it as a static array inside Player (the class, not the instance) itself. Why not? Two other considerations were: 1. Player is not very likely to be subclassed, so the usual addition of an interface might not be needed. But maybe it is. 2. Static methods are easy because you don't need to carry object references around. But, as I already have indicated in an earlier post, self-managing classes turn out not to fit well with the style of component management and XML parsing that we have started to use, so that a PlayerManager class already needs to be considered. So I probably (though somewhat reluctantly) have to agree with you.... Long live the proliferation of classes! :-( Erik, |