Re: Many questions about partially constructed objects !!!???



Yes Maarten,

I agree with your story and design decisions etc. I, just like you,
like to keep constructors as simple as possible to prevent any nasty
problems because constructors are a bad place to have problems as this
example more or less illustrates. When the constructors fails the whole
object construction fails which makes it as good as impossible to fix
any little problems inside the object. With your design and special
methods it's still possible to fix or investiage any little problems so
it's more flexible.

However your/this design has limitations. It's more difficult to write
abstract/general code/objects/classess which can create other objects
and classess. To do so there needs to be a common framework and the
only common framework is delphi's constructor/destructor framework.
Your design for example is only your design/framework... if I use your
design for example... then the design can no longer create any other
objects because those do not have the necessary framework in place.

This is related to my other post about passing a constructor. If that
was possible then it would be possible to write functions which can
generate any kind of object. Delphi can already do this ofcourse... the
problem is with special constructors which have/need parameters.

The problem I now face is the following:

I want to create and object. This object has an array of byte. The
array of byte also has to be allocated. I would like to do this in the
constructor so that it's an all or nothing situation. If everything
gets allocated then I can use the object. If some part fails then I
have no use for the object.

So I would like to pass a parameter to the constructor... and maybe I
even want to write a function like so:

function CreateObject( const ParaClassType : Tclass; var ParaObject :
Tobject ) : boolean;
begin
try
ParaObject := ParaClassType.Create;
result := true;
except
result := false; // hopefully inherited create/access violation
exception won't cause a
failure here..
// probably not since Tobject probably
catches it...
end;
end;

I saw your post in the other thread... but I don't like assembler at
all... also it seems to pass longwords only ? Well that will do for
now... but general parameters would be cooler... maybe variants can
help ?

Anyway I'll check out your code to see if I understand some of it and
how it works..

Bye,
Skybuck

.



Relevant Pages

  • Re: Classes derived from ServicedComponent do not support constructors with arguments?
    ... You have to be careful when you design this stuff as well. ... if you are going to use transactions, or just in time activation, or object ... implementations, with default, parameterless constructors. ... Classes derived from ServicedComponent do not support ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [Class]Ridiculous question
    ... These schools of thought are not opposite or immiscible but rather complementary and both can be used in the same design. ... aa.setIndexation(sosaRoot2); ... On the other side of the coin there is something called POJO. ... There are also a myriad of configurations available for the average Swing object, which would require a confusing myriad of constructors to support if they went the POJO route, so again Beans win here by virtue of simplicity. ...
    (comp.lang.java.help)
  • Re: Where to put user interface
    ... >constructors to get the data needed to build an object. ... >used to create an object initialized with the arguments from the I/O. ... whole slew of design issues they either may not be ... Comeau C/C++ with Dinkumware's Libraries... ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Constructor inheritance
    ... because we often don't want the same set of constructors on derived ... :> Inheritance is supposed to promote code resuse. ... a much more preferable OO design is to instantiate a Thread ... :> So it was surprising the compiler generates missing default constructors. ...
    (comp.lang.java.programmer)