Re: Defining a constructor in an Interface



In article <42C33E26.3F01@xxxxxxxxxxxxx>,
Lee Fesperman <firstsql@xxxxxxxxxxxxx> wrote:
>
>As others have suggested, require a no-args constructor and define a
>class initializer
>in the interface, like init(...). It really is a better way.

I have based my (non-factory-based) immutables on getting all their
state through the ctor, but the question posed indicates that this
isn't always feasible.

Is an init() method considered a viable way to make immutable objects?
While you could write init() in such a way that any calls beyond the
first are ignored, it seems a bit kludgy. If nothing else, clients
could end up using instances that haven't had init() called on them
yet and then their contents _can_ theoretically change at some later
point.

Cheers
Bent D
--
Bent Dalager - bcd@xxxxxxx - http://www.pvv.org/~bcd
powered by emacs
.


Quantcast