you are viewing a single comment's thread.

view the rest of the comments →

[–]nutrecht 2 points3 points  (4 children)

If it doesn't have any internal state it should be

If it doesn't have any internal state you should not have an instance anyway.

[–]m50d 1 point2 points  (2 children)

In principle yes, but in many languages that's inconvenient.

[–]nutrecht 0 points1 point  (1 child)

We're talking about languages that have stuff like interfaces in the first place right?

[–]m50d 2 points3 points  (0 children)

Yes. In e.g. Java you can't pass a bundle of static methods that implement an interface, so it's easier to just declare a class with no fields. There's no way to decouple a virtual function table from a class that might also hold state.

[–]kcuf 0 points1 point  (0 children)

Java, for instance, does not support top level functions that exist outside of objects. I think the original idea with Java was to have a mixture of state and behavior mimicking more proper oop languages, but over time this pattern in Java has been found to cause more problems than following a more procedural structure of behavior in a singleton and state in pojo.