Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!microsoft!alonzo From: alonzo@microsoft.UUCP (Alonzo GARIEPY) Newsgroups: comp.lang.eiffel Subject: Re: Should a constructor do "work"? Message-ID: <55776@microsoft.UUCP> Date: 11 Jul 90 18:53:45 GMT References: <55236@microsoft.UUCP> <181@dumbcat.sf.ca.us> <359@eiffel.UUCP> <519@tetrauk.UUCP> Reply-To: alonzo@microsoft.UUCP (Alonzo GARIEPY) Organization: Microsoft Corp., Redmond WA Lines: 19 This doesn't seem like such a big problem. If it is possible for an object to exist in a partially initialized state, that should be taken into account by the class invariant. Some kind of flag value will suffice to identify the condition of the object. After a successful allocation in a constructor, the first thing to do is set this partial initialization flag (an operation guaranteed to succeed). The constructor can then return, or it can attempt to fully initialize the object. If the initialization succeeds, the last operation in the constructor is clearing the partial initialization flag (another guaranteed successful operation). If the actual memory allocation fails, the exception can be propagated upwards until it results in a valid state. One hopes there is no need to return nil pointers as the result of failed construction, but special code to handle nil does allow it to work relatively well. alonzo@microsoft