3 ms·
Performing the calculation in the constructor may not go well if many objects are created, but not very many are computed. The example seems more of a functor t
by cudgy 4y ago
Performing the calculation in the constructor may not go well if many objects are created, but not very many are computed. The example seems more of a functor than a full blown class.
Also, classes along with static methods can be used to create a namespace to avoid polluting the global namespace, grouping similar operations together.
- lionkor 4y agoI may be missing something, but free functions + namespaces do namespacing better than classes with static methods, no?
- cudgy 4y agoAssuming there is no state shared between them, they are basically equivalent in function. Perhaps there is an advantage to namespaces regarding call overhead but that would be implementation dependent. Some languages do not provide namespaces but do provide classes, so static methods are all that is available.