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*

4
  • 1
    The language you're using doesn't allow overloading constructors? Commented Jun 29, 2012 at 5:47
  • 1
    I am using Java.So Yes, it does allows and I think that could be one way to deal with this Commented Jun 29, 2012 at 7:19
  • 2
    I would note that if you have no public way to set class members after the fact, your class is effectively immutable. By allowing a public setter, you class now becomes mutable, and you may need to take this into consideration if you depended on immutability. Commented Aug 7, 2014 at 3:26
  • I would say that if it needs to be set for your object to be valid, put it in every constructor... if it's optional (has a reasonable default) and you don't care about immutability, put it in a setter. It should be impossible to instantiate your object into an invalid state or after instantiation put it into an invalid state wherever possible. Commented Oct 30, 2014 at 17:13