OO conventions

Magnus Lycka lycka at carmen.se
Thu Feb 2 10:29:15 EST 2006


Alex Martelli wrote:
> Steven D'Aprano <steve at REMOVETHIScyber.com.au> wrote:
>>And now, at long last, the image object actually is an image. So why make
>>this a two step process? Whatever the Image() initialization does, why
>>can't it be done automatically when you read the file?
> 
> "Two-step construct" ("2SC") is a reasonably well-known and widely
> useful idiom, and it can serve several kinds of purposes, many but not
> all of which are tied to persistence. 

I've seen it used as a C++ coding standard when e.g. loading
instances from databases (Person p=Person(); p.init(id);)
since it was considered bad to have code in the constructor
which could throw exceptions. If you make a new Person on
the heap, and catch an exception from the constructor, are
you sure that you delete the object?



More information about the Python-list mailing list