Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

OOP is routinely used with stateful, mutating objects; it has been hailed as a good way to manage that paradigm. If mutation is bad, so most objects don't mutate, you're talking about a functional niche in OOP, not mainstream OOP.

A class may need a setter function for some boring, pragmatic reason like, say:

- the language doesn't have keyword parmeters: constructors have only positional parameters

- the class has a large number of properties.

- most users set only a small subset of the properties, defaulting the rest. (And you can't easily predict which subsets are popular enough to get their own constructor variants.)

In that situation you might want to just construct the object in two steps: default everything and set a few selected properties (and then don't touch them). It's de facto immutable, just not around construction time.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: