Why am I seeing so many instantiable classes without state?
Posted
by
futlib
on Programmers
See other posts from Programmers
or by futlib
Published on 2012-10-12T04:52:31Z
Indexed on
2012/10/12
9:50 UTC
Read the original article
Hit count: 188
I'm seeing a lot of instantiable classes in the C++ and Java world that don't have any state.
I really can't figure out why people do that, they could just use a namespace with free functions in C++, or a class with a private constructor and only static methods in Java.
The only benefit I can think of is that you don't have to change most of your code if you later decide that you want a different implementation in certain situations. But isn't that a case of premature design? It could be turned into a class later, when/if it becomes appropriate.
Am I getting this wrong? Is it not OOP if I don't put everything into objects (i.e. instantiated classes)? Then why are there so many utility namespaces and classes in the standard libraries of C++ and Java?
Update: I've certainly seen a lot examples of this in my previous jobs, but I'm struggling to find open source examples, so maybe it's not that common after all. Still, I'm wondering why people do it, and how common it is.
© Programmers or respective owner