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.

6
  • 1
    "public int Foo { get; private set; }" That class is no longer immutable because it can change itself. Thanks, though! Commented Jul 21, 2015 at 17:47
  • 4
    The class described is immutable, as it doesn't change itself. Commented Jul 21, 2015 at 17:48
  • 1
    My actual class is a bit more complex that the MWE I gave. I'm after real immutability, complete with thread safety and class-internal guarantees. Commented Jul 21, 2015 at 18:01
  • 4
    @kdbanman, and your point is? If your class only writes to the private setters during construction, then it has implemented "real immutability". The readonly keyword is just a poka-yoke, ie it guards against the class breaking the immutablity in future; it isn't needed to achieve immutability though. Commented Jul 21, 2015 at 18:09
  • 3
    Interesting term, I had to google it - poka-yoke is a Japanese term that means "mistake-proofing". You're right! That's exactly what I'm doing. Commented Jul 21, 2015 at 18:14