Static methods – what are they really?

Static methods are simple little creatures. They don’t need an object to be instantiated, it is obvious which method you are calling, and it is clear what it does and what it returns.

They don’t interact with the ‘instance’ world, they deal only with their own kind. They sit in their own little bubble and happily interact together with their static neighbours and families.

Many people hate static methods? Why? It’s not object-oriented. It is as simple as this. Dependency injection, polymorphism, inheritance, constructors – all these things are irrelevant when we talk about ‘static’ methods.

The concept of a non-static method means a class needs to be instantiated before you can manipulate the data within that object. This makes perfect sense. The class is the template, the object is a physical representation of that template.

Static methods are really just a legacy hang-over from pre-OO procedural languages. So basically, Java allows you to write non-OO code.

Here’s a link I found after typing some of this article, which nicely reflects my POV in another way:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s