Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are static utility methods not pure Object Oriented Programming? [closed]

People say Static utility methods are bad in OOP because they don't follow the OOP way of doing things.

I know static utility methods come from the more traditional procedural programming paradigm. And people say true OOP would be modelling the real world in objects sense encapsulating state & behaviour into one.

Is this true?

If so, is it best practice in modern OOP to not use static utility methods at all? Or is it still common to use them? Would this latter question be more of a 'depends' situation?

like image 745
SoftwareDeveloper Avatar asked Jul 29 '26 05:07

SoftwareDeveloper


1 Answers

Static methods (without side-effect) are in Computer Science named functions.

And I think it is general consensus that Functional Programming is superior.

Object Oriented Programming has the advantage that state is imminent to it, and in comparison to FP can make things more straight-forward.

However in the case of static methods functions are fine. Fine for low-level values. If the case is many functions operating on more complex classes, one may have an issue. Maybe those classes are unnecessarily complex, the logic too convoluted.

Compare BigDecimal with a theoretic version with static methods for add, multiply and so on. Functions would probably be better readable.

like image 187
Joop Eggen Avatar answered Jul 31 '26 20:07

Joop Eggen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!