JavaBean, POJO, VO, DTO, DAO 异同

来源:互联网 发布:行知实验园 编辑:程序博客网 时间:2024/06/07 20:42

refs:

https://dzone.com/articles/database-interaction-dao-and

http://java-base.com/javabean-vs-dto-vs-pojo-jknb/


Plain Old Java Object (POJO)

The name is used to emphasize that a given object is an ordinary Java Object, not a special object. It has absolutly no restrictions.

POJO, or Plain Old Java Object, is a normal Java object class (that is, not a JavaBean, EntityBean 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.


JavaBean

JavaBean is a simple java class or POJO, but with some restrictions. This is the main difference between a POJO and a JavaBean. Some of the restrictions are:

  • JavaBean should provide default public constructor.
  • JavaBean should provide property accessor methods (getters and setters).
  • JavaBean should be serializable.

JavaBean is a example of POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods that follow a simple naming convention.

Value Object (VO)

Value Object is simple object that holds values. The VO should be entirely immutable.

Data Transfer Object (DTO)

DTO is serializable object, which is used for transfering data between different processes. It shouldn’t be mixed with VO. This is exposed as design pattern.

Data Access Object (DAO)

This is an object, which provides mechanism for accessing objects from the persistance layer. This is actually one of the most popular design patterns.


0 0
原创粉丝点击