Skip to main content

All Questions

6 votes
6 answers
5k views

Should constructors ever be used only for side-effects?

Summary: Why is it wrong to design a constructor only for its side effects, and then to use the constructor without ever assigning its return value to a variable? I'm working on a project that ...
Brian H.'s user avatar
  • 179
27 votes
4 answers
10k views

Legitimate "real work" in a constructor?

I am working on a design, but keep hitting a roadblock. I have a particular class (ModelDef) that is essentially the owner of a complex node tree built by parsing an XML schema (think DOM). I want to ...
Gurtz's user avatar
  • 389