Plain Old Java Objects (POJO)

What is a POJO?

"A POJO is a simple ordinary java object that does not extends classes or implements interfaces from any frameworks or APIs"

The term "POJO" is mainly used to denote a Java object which does not follow any of the major Java object models, conventions, or frameworks. A POJO is a Java object that doesn't implement any special interfaces ,extends classes, defined in frameworks and APIs. Ideally speaking, a POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification. i.e a POJO should not have to.



  1. Extend prespecified classes, as in
    public class Foo extends javax.servlet.http.HttpServlet { ...
    
  2. Implement prespecified interfaces, as in
    public class Bar implements javax.ejb.EntityBean { ...
    
  3. Contain prespecified annotations, as in
    @javax.persistence.Entity public class Baz { ...


However, due to technical difficulties and other reasons, many software products or frameworks described as POJO-compliant actually still require the use of prespecified annotations for features such as persistence to work properly.

The Benefits of POJOs

Decoupling the application code from the infrastructure frameworks is one of the many benefits of using POJOs. They also simplify development because rather than being forced to think about everything - business logic, persistence, transactions, etc. - at once, you can focus instead on one thing at a time. You can design and implement the business logic and then, once that's working, you can deal with persistence and transactions.
POJOs also accelerate development. You can test your business logic outside of the application server and without a database. You don't have to package your code and deploy it in the application server. You also don't have to keep the database schema constantly in sync with the object model or spend time waiting for slow-running database tests to finish. Tests run in a few seconds and development can happen at the speed of thought - or at least as fast as you can type!



An Example of POJO can be as follows,


public class MyBean {
 
    private String someProperty;
 
    public String getSomeProperty() {
         return someProperty;
    }
 
    public void setSomeProperty(String someProperty) {
        this.someProperty = someProperty;
    }
}

Thanks wikipedia

Comments

Popular posts from this blog

OOPS Concepts with realtime examples

What is an interface?

Asynchronous Messaging