Wednesday 3 October 2012

What is POJO?

POJO (Plain Old Java Object), is a normal Java object class (that is, not aJavaBean, EntityBean, SessionBean etc.) and does not serve any other special role nor does it implement any special interfaces of any of the Java frameworks. This term was coined by Martin Fowler, Rebbecca Parsons and Josh MacKenzie who believed that by creating the acronym POJO, such objects would have a "fancy name", thereby convincing people that they were worthy of use.

POJO是一个简单的、正规Java对象,它包含业务逻辑处理或持久化逻辑等,但不是JavaBean、EntityBean SessionBean等,不具有任何特殊角色和不继承或不实现任何其它Java框架的类或接口。POJO有一些private的参数作为对象的属性。然后针对每个参数定义了get和set方法作为访问的接口。

Example: 

public class customer {
   private long id;
   private String firstName;
   private String lastName;
   private String address;

   public void setId(long id) {
      this.id=id;
   }

   public void setFirstName(String firstName) {
      this.firstName=firstName;
   } 

   public void setLastName(String lastName) {
      this.lastName=lastName;
   } 

   public void setAddress(String address) {
      this.address=address;
   } 

   public void getId() {
      return id;
   }

   public void getFirstName() {
      return firstName;
   } 

   public void getLastName() {
      return lastName;
   } 

   public void getAddress() {
      return address;
   }

No comments:

Post a Comment