Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 1
    This is poor advice. You should not allow objects to be in an invalid state. That's what the constructor is for. If you need complex logic then use the factory pattern. Commented Aug 4, 2015 at 9:42
  • 1
    Constructors are there to establish the class invariants, the sample code doesn't help to assert that at all. Commented Aug 4, 2015 at 9:44
  • @Alex I think base of this idea might be true. imagine an initial sate that needs to be transferred to other state in order to be transferable to other states. although this might be a logical mistake by developer to integrate some operations. Commented Mar 31, 2022 at 12:32