Timeline for how complex a constructor should be
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 11, 2022 at 1:13 | comment | added | Ed Swangren | @pqnet: "and the method can ensure the object is always in a good state" - like a constructor is meant to do? | |
Oct 11, 2022 at 0:15 | comment | added | Ed Swangren | @pqnet: if init() fails, what then? Throw an exception? What's the advantage exactly? You just lost the stack trace along with everything else, and why couldn't that have been handled just as well in the constructor to begin with? Useless wrapper methods are a pain | |
Jan 28, 2020 at 15:28 | comment | added | CharonX |
@pqnet With init() methods I see the issue that you end up with temporal coupling. You can do X with this class, but you have to init() it first. So now you need to add checks to every function call if the class is really initialized and handle the possible failure events...
|
|
Mar 12, 2018 at 11:27 | comment | added | pqnet |
the advantage, in my opinion, of the init method is that handling failure is a lot easier. In particular, the return value of the init method can indicate whether initialization is successful, and the method can ensure the object is always in a good state.
|
|
Nov 10, 2017 at 8:03 | review | Late answers | |||
Nov 10, 2017 at 14:48 | |||||
Nov 10, 2017 at 7:45 | review | First posts | |||
Nov 10, 2017 at 8:55 | |||||
Nov 10, 2017 at 7:43 | history | answered | Pavel Khrapkin | CC BY-SA 3.0 |