Re: Good style for memory management?



Paul Davis wrote:
> [snip]
>
> There is another thing that I always feel should be pointed out about
> using the ctor()/init() pair. Generally, all objects have a lifetime
> >from the call to the constructor to the destructor.  And its a single
> state lifetime.  Ie, its just alive.  Using the ctor()/init()
> introduces a second state.  you have pre-init() and post-init().   You
> can no longer reasonably make the assumption that an object has been
> initialized. Which means you have to check for it.  Everywhere. For me
> its a headache I can avoid, so I do.
> 
> Plust I just find this annoying to look at:
> 
> MyObject* b = new MyObject() ;
> b.init( "Hello, World!" ) ;

Wholehearedly agree.  At work I'm maintaining a project (not written by
me or even my colleagues) in which most objects have dummy constructors
and almost everything is bumped into properties.  Objects are loaded from
database by ID.  So (it is Java) objects are created like this:

	object = new SomeObject ();
	object.setID (some_id);
	object.load ();

And that is a nightmare to work with.

(To make it even worse, almost all setters are public, even for properties
that are meant to be computable and not settable from outside.  Side issue,
though.)

Paul



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]