|
From: Luigi B. <lui...@gm...> - 2010-02-17 15:27:22
|
On Wed, 2010-02-17 at 16:11 +0100, Ferdinando Ametrano wrote: > On Wed, Feb 17, 2010 at 10:21 AM, Luigi Ballabio > <lui...@gm...> wrote: > > On Tue, 2010-02-16 at 19:09 +0000, na...@us... wrote: > >> added more Coupon inspectors > > > > We're duplicating code all over the place---they're all basically the > > same loop. Why don't you write a nextCoupon() method instead and call > > whatever method you want on the result? > > you're right and this is true for both nextCashFlow and nextCoupon, > their "previous" variants, and their CashFlows and Bond flavors > > Anyway if bond_ is a shared_ptr<Bond> you would then have to write > > (*BondFunctions::nextCashFlow(*bond_))->date(); > > instead of > > bond_->nextCashFlowDate(); Worse---You'd have to check for a null iterator first. Ok, I can see it's good to have the whole bunch of functions for convenience. Plus there's the aggregation thing. It might still be worth to write the common loop in a nextCoupon() method (private, if need be) so that at least the functions returning a date can call it and remove a good part of the duplication. For the aggregation, I don't know. I had though of returning a range (begin,end) of the cashflows on the same date, but it wouldn't work if there was a non-coupon cashflow between two coupons. Maybe a composite, as you say. Well, I'll let you know if I get any ideas... Luigi -- A programming language is low-level when its programs require attention to the irrelevant. -- Alan Perlis |