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.

25 comments: