Friday, October 24, 2008

Utils classes and NOJOs

A style of class that is a frequent complement to NOJOs (introduced in my previous article) are classes with only static methods. They might be called SomethingUtil or SomethingHelper.

People will often know what you mean if you say "a Utils" class, so I won't propose anything different here. I had wanted to propose a catchier name - SOJOs (Static Only Java Object) but the acronym (with a completely different meaning) is already taken by the SOJO project. In a comment on my NOJO article, John Q Public said he uses the term "function buckets" and I'm sure he's talking about the same thing.

Why do people write Utils classes?

If you have NOJOs then your methods have got to go somewhere. People who prefer the NOJO style often like to create static methods on Utils classes for those methods.

Are Utils classes a Good Thing?

Again, left as an exercise for the reader. An article from my old blog might help to hint about my views (although it is not specifically about this subject) without me having to stay up all night writing more. It seems like people aren't shy about expressing their opinions in comments - some of which I completely agree with, so I'll leave it as an exercise for comment writers as well as the reader (cheeky, I know).

In defence of my previous article

I didn't make any judgements in my previous article - mostly through lack of time but also because I want the term NOJO to be understood without being confused with whether it's any good or not. I am merely making an observation and suggesting a name for a thing I see frequently, that is poorly served by current names. I found it interesting how many people suggested that there was already a term for NOJO but none of their suggestions were entirely accurate.

Copyright © 2008 Ivan Moore

Thursday, October 23, 2008

Is that a POJO or a NOJO?

The term "POJO" is widely used in the Java programming world, but is sometimes used to mean something more specific than what was originally intended.

Furthermore, such code (whether called POJO or not by its authors) is a style which I think would be useful to give a specific name to.

What's a POJO?

The original meaning of POJO was a plain old Java object - that is, an object that isn't tied to a framework (for example, having to implement specific interfaces). A concrete example of a non-POJO would be entity beans (from EJB).

Introducing NOJOs

NOJOs are (instances of) classes which define fields, setters and getters but no other methods. They are popular in enterprise Java code and I think deserve a specific term, to distinguish them from the rather general term POJO.

NOJO stands for "Non Object-oriented Java Object". Although it might sound "negative" it is merely intended to be accurate and have a catchy acronym.

What defines an object?

An "object" (in object-oriented programming) has identity, state and behaviour. A NOJO has identity and state. A function has behaviour but not state. An object has identity, state and behaviour.

Why do you need a term for NOJO?

In many programming languages, there is a language construct for NOJOs (or something very similar) - e.g. "struct" in C, or "record" in Pascal. In Java there isn't an equivalent language construct - so the term NOJO is intended to mean the use of a Java class to implement such a thing, to make it easier to talk about such code.

Are NOJOs a Good Thing?

Left as an exercise for the reader.

Sunday, October 12, 2008

Blog moved here

Joe Walnes, the best developer I've ever worked with, got me started blogging (many thanks Joe) by hosting my blog on his server. Now the time has come for him to retire his server, and so my blog has moved here. I'll be writing more articles soon - I've got a backlog of programming in the small ideas to write up - but have been very busy with work, being (co) programme chair of my favourite conference (SPA), build-o-matic and just trying to keep up with the world.