From: Erik V. <eri...@xs...> - 2012-07-27 12:30:23
|
Stefan, All details aside, effectively you remove the (old-style) Portfolio holdall objects (except for the Bank, where four of such containers are really needed, and now are renamed to BankPortfolio). That removes a level of indirection in many calls, so it sounds like a real improvement. A few more notes: > The default implementation of Portfolio is a PortfolioSet: Here all items are > thrown into one bucket, each ownable item is unique (has its own id), thus it > is implemented as a set. > > General Remark: If items are not-unique, there are other structures to deal > with those (non-unique items implement Countable and get stored in a > Wallet). > > A more sophisticated variant is PortfolioMap. Here the portfolio is structured > by a "type" attribute of the items. I notice that you are omitting PortfolioList. Please be aware, that in some cases sequence matters. For instance, IIRC, the President's certificate is occasionally retrieved via .get(0). Of course, there are ways around that. > * A third example: BaseTokens and BonusTokens > > If both of them have to be stored inside a Portfolio<Token> (because Token > extends OwnableItem<Token>, there is no way to separate them. > > Solutions: > a) Add two HashSetState<BaseToken> and HashSetState<BonusToken> in > parallel. > > b) Put the portfolio inside a model and provide .getBonusTokens() and > .getBaseTokens() methods. > > c) Make Tokens implement Typable<Class<? extends Token>> and return > the class as type. > Then Tokens can be stored inside PortfolioMap<Class<? extends Token>, > Token> and portfolio.get(BaseToken.class) and > portfolio.get(BonusToken.class) works. I wonder why you omit d) Create two portfolios Portfolio<BaseToken> and Portfolio<BonusToken>. Is that because in some games BaseTokens can change into BonusTokens? (Example: 18FL). Erik |