From: Stefan F. <ste...@we...> - 2012-09-02 21:05:44
|
It might sound more complicated, but it is a consequence of the indirect access to Wallets and Portfolios. The link between the Wallet and the Owner is defined once and forever by creating a Wallet with the Owner as the parent. It does not matter where the Wallet lives (e.g. inside a variable of the owner itself, inside a PortfolioModel or stored at a completely different object). At the time of adding money the Owner is NOT asked for its wallet, but the wallet for the according owner is provided by the WalletManager by asking for the correct Wallet for the (Owner, Type) combination. A potential code snippet for an aggregate BankMoneyModel class: private Wallet<Currency> bankWallet; private Wallet<Currency> ipoWallet; private Wallet<Currency> poolWallet; public BankMoneyModel(Bank bank) { bankWallet = Wallet.create(bank, "wallet", Currency.class); ipoWallet = Wallet.create(bank.getIpo(), "wallet", Currency.class); poolWallet = Wallet.create(bank.getPool(), "wallet", Currency.class); bankWallet.addModel(this); ipoWallet.addModel(this); poolWallet.addModel(this); } public int getCash() { return bankWallet.value() + ipoWallet.value() + poolWallet.value(); } In the example above you could wire money to Bank, Pool or Ipo and it has the same net effect to the BankMoneyModel. The MoneyOwner interface is only a helper/legacy interface to allow an easy access the cash value. On 09/02/2012 10:30 PM, Erik Vos wrote: >> However it might make the code easier to assume that IPO/Pool etc. have >> their own cash wallet to make the item buying code easier: >> Then the counterparty of the item transaction is identical to the > counterparty >> of the accompanying cash transaction. > > To me, that sounds like making life more complicated rather than making it > simpler. > Why then not have the Bank portfolios contain a reference to the Bank > Wallet? > Or indeed, include into every Portfolio a reference to its owner's Wallet. > > Erik. > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Rails-devel mailing list > Rai...@li... > https://lists.sourceforge.net/lists/listinfo/rails-devel > |