3 ms·
If I don't explicitly need "state" (user-data in models or GUI-state in view-models) I leave it out. Most of the time I use classes and their objects as a stat
by k__ 12y ago
If I don't explicitly need "state" (user-data in models or GUI-state in view-models) I leave it out.
Most of the time I use classes and their objects as a stateless bag of related methods. Like namespaces...
- chriswarbo 12y agoIMHO classes are a "jack of all trades, master of none". They're sort of like namespaces, a bit like modules, kind of like closures, somewhat like types, almost like first-class functions, etc. On a somewhat related note, http://www.newspeaklanguage.org http://www.newspeaklanguage.org uses classes for all kinds of things, including namespaces.
- k__ 12y agolol, yes. But I have to admit, the dynamic properties of objects make them much more versatile than namespaces or modules. If I would use them only as namespaces, by defining every of my (stateless) methods static, they would work exactly as a namespace. But when they're bound to an object instead, I can switch out implementation details easily when needed. So I would consider classes and their objects to be a more powerful version of namespaces.