The Artima Developer Community
Sponsored Link

Weblogs Forum
Two Stage Construction in C++ versus Initializing Constructors

15 replies on 2 pages. Most recent reply: May 3, 2005 8:44 AM by Harrison Ainsworth

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 15 replies on 2 pages [ « | 1 2 ]
Harrison Ainsworth

Posts: 57
Nickname: hxa7241
Registered: Apr, 2005

Re: Two Stage Construction in C++ versus Initializing Constructors Posted: May 3, 2005 8:44 AM
Reply to this message Reply
Advertisement
I look at this from a larger perspective.

The initialization of an object with a constructor -- that is, single-stage construction in this context -- is a cornerstone of C++'s strict typing semantics. It means that if an object exists, then it will work fully and properly. It is an aspect of encapsulation, that conveys a guarantee to software built upon it.

Two-stage construction means it is possible to have objects that do not actually represent invariants. Code using such classes is not really getting a strictly enforced type at all, and has to be able to handle anomalous cases too. In a sense some of the responsibility and information has leaked out of the class. The notion of construction is vitiated.

To deliberately eschew proper construction goes very much against the grain. Your most prominent cause was to reduce the amount of code written, and this is nowhere near justification. You cannot compromise higher structural integrity for the sake of a bit of inconvenient work.

(The other reasons were incidental: you would be handling them elsewhere anyway. And Mr Wilson dealt with them earlier.)

Maybe this sounds too strict. But I think strictness is good. It is likely to benefit the product.

Flat View: This topic has 15 replies on 2 pages [ « | 1  2 ]
Topic: I Hope I Work with Mediocre People Previous Topic   Next Topic Topic: Bolt-Ins for Contract and Extension Classes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use