Added one more rule for POJO (#33895)

Added one more rule that has to be obeyed when creating POJO.
This commit is contained in:
Nikola Stevanović
2019-03-24 18:26:06 +01:00
committed by Christopher McCormack
parent e880eda783
commit 043676aa90

View File

@ -27,6 +27,31 @@ public class Bar implements javax.ejb.EntityBean {
}
```
4. For any class field which is marked as private it must have getter and setter methods alongside it. Also it must have EMPTY constructor if custom constructor declared.
```
public class Car {
private int gear;
// default constructor
public Car() { }
// custom constructor
public Car(int car){
this.car = car;
}
public int getGear() {
return this.gear;
}
public void setGear(int gear){
this.gear = gear;
}
}
```
Therefore a Java Object qualifies as a POJO only when it is free from the above modifications. It therefore follows that a POJO is not 'bound by any restrictions' other those prescribed by the formal Java language specification.
POJO is usually used to describe a class that doesn't need to be a subclass of anything, or implement specific interfaces, or follow a specific pattern. It has properties, getters and setters for respective properties. It may also override Object.toString() and Object.equals().