Posted by
Vadim Ogranovich-3 on
Oct 26, 2002; 12:59pm
URL: http://quantlib.414.s1.nabble.com/call-for-void-constructors-tp10165p10167.html
From: Luigi Ballabio [mailto:
[hidden email]]
...
At 7:16 PM -0500 10/25/02, Vadim Ogranovich wrote:
>I find it inconvenient that FdDividendAmericanOption, etc.
have no void
>constructor. I was working around the problem of zero
dividend time and
>wanted to overload FdDividendAmericanOption with a new
class,
>FdDividendAmericanOption2, that will chop off the zero time
dividend and
>pass only the remaining dividends to
FdDividendAmericanOption.
>
>However the problem in actually writing
>FdDividendAmericanOption2::FdDividendAmericanOption2 is
that I have very
>limited "coding space" to check whether I need to chop off
the first element
>and, if yes, to actually chop it off. Indeed, all these
calculations need to
>happen before the base class, FdDividendAmericanOption,
gets initialized by
>its constructor.
Well, not really. The constructor of
FdDividendAmericanOption doesn't
perform any calculation---it just stores the input data.
[Vadim] Well, this will work, but it's a HACK and ,worse, it
breaks "encapsulation" of FdDividendAmericanOption since now I need to know
that its constructor doesn't perform any calculation, and those people who
modify FdDividendAmericanOption class need to know that too, otherwise they
will break my new class. Use of init() is free of these drawbacks since all
I need to know is to create an empty instance and then initialize it with
init, in other words I just need to know the interface.
I agree that it would be desirable that default constructor
created a valid instance, but it's not of really high importance, especially
if an uninialized instance will crash the program.
To make this discussion a little bit more concrete (but not
too much :-)) consider writing a function which given option characteristics
returns the most efficient pricer for that option, e.g.
SingleAssetOption * getMostEfficientPricer(...).
Without default constructors the argument list of the
function must include all parameters possibly needed by actual constructors
(fat parameter list). This is certainly not good as this list is likely to
change when you add new pricers or add parameters to the old constructors.
Again, lack of default constructors is not an
un-surmountable problem, it's just an inconvenience that precludes some good
programming techniques.
Thanks, Vadim
--------------------------------------------------
DISCLAIMER
This e-mail, and any attachments thereto, is intended only for use by the
addressee(s) named herein and may contain legally privileged and/or
confidential information. If you are not the intended recipient of this
e-mail, you are hereby notified that any dissemination, distribution or
copying of this e-mail, and any attachments thereto, is strictly prohibited.
If you have received this e-mail in error, please immediately notify me and
permanently delete the original and any copy of any e-mail and any printout
thereof.
E-mail transmission cannot be guaranteed to be secure or error-free. The
sender therefore does not accept liability for any errors or omissions in
the contents of this message which arise as a result of e-mail transmission.
NOTICE REGARDING PRIVACY AND CONFIDENTIALITY
Knight Trading Group may, at its discretion, monitor and review the content
of all e-mail communications.