P
Peter Morris [Droopy eyes software]
This is what Anders says
=====
The problem with Delphi's model (allowing constructors to be called on
an already constructed object) is that it makes it impossible to have
provably immutable objects. Immutability is an important concept because
it allows applications to hand objects to an external party without
first copying those objects and still have a guarantee that the objects
won't be modified. If constructors can be called on already constructed
objects it obviously isn't possible to make such guarantees. In Delphi's
case that may be ok since Delphi doesn't really make type safety
guarantees anyway (you can cast any object reference to a
pointer-to-something and start poking away), but .NET goes further with
type safety and this would be a big hole.
=====
I'm not sure I agree though. If C# can stop me from modifying a readonly
member outside of a constructor then surely it can also prevent me from
calling a base constructor too?
"Chrome" (http://www.chromesville.com) will apparently let you call the base
constructor at any point you wish and the constructors are still not
accessible from standard methods.
Am I missing something in this reply? I don't think I am but you never know
Pete
=====
The problem with Delphi's model (allowing constructors to be called on
an already constructed object) is that it makes it impossible to have
provably immutable objects. Immutability is an important concept because
it allows applications to hand objects to an external party without
first copying those objects and still have a guarantee that the objects
won't be modified. If constructors can be called on already constructed
objects it obviously isn't possible to make such guarantees. In Delphi's
case that may be ok since Delphi doesn't really make type safety
guarantees anyway (you can cast any object reference to a
pointer-to-something and start poking away), but .NET goes further with
type safety and this would be a big hole.
=====
I'm not sure I agree though. If C# can stop me from modifying a readonly
member outside of a constructor then surely it can also prevent me from
calling a base constructor too?
"Chrome" (http://www.chromesville.com) will apparently let you call the base
constructor at any point you wish and the constructors are still not
accessible from standard methods.
Am I missing something in this reply? I don't think I am but you never know
Pete