POJO: A Plain Old Java Object or POJO is a term initially introduced to designate a simple lightweight Java object, not implementing any javax.ejb interface. POJO is an acronym for Plain Old Java Object. The name is used to emphasize that the object in question is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean.
Value Object (VO): A Value Object or VO is an object such as java.lang.Integer that hold values (hence value objects).
Data Transfer Object (DTO): Data transfer object (DTO), formerly known as value objects or VO, is a design pattern used to transfer data between software application subsystems. DTOs are often used in conjunction with data access objects to retrieve data from a database.
The difference between data transfer objects and business objects or data access objects is that a DTO does not have any behaviour except for storage and retrieval of its own data (accessors and mutators).
DTO vs VO
- DTO - Data transfer objects are just data containers which is used to transport data between layers and tiers .It mainly contains of attributes ,You can even use public attributes without getters and setters .Data transfer objects do not contain any bussiness logic.
- Analogy: Simple Registration form where you have attributes usename,password and email id . when you sumbit this form . In your servlet RegistrationServlet.java file you will get all the attributes from view layer to business layer where you pass the attributes to java beans and then to the DAO or the persistence layer . DTO’s helps in transporting the attributes from view layer to bussiness layer and finally to the persistence layer .
- DTO was mainly used to get data transportd across the network efficiently , it may be even from JVM to another JVM .
DTOs are often java.io.Serializable – inorder to transfer data across JVM
VO - A Value Object [1,2] represents itself a fix set of data and is similar to a Java enum. A Value Object’s identity is based on their state rather than on their object identity and is immutable. A real world example would be Color.RED, Color.BLUE, SEX.FEMALE etc.
POJO V/S JavaBeans
- The Java-Beanness of a POJO is that it’s public attributes are all accessed via getters and setters that conform to the JavaBeans conventions. e.g. private String foo; public String getFoo(){…} public void setFoo(String foo){…};
- JavaBeans must implement Serializable and have a no-argument constructor. where as in POJO doesnot have these restrictions .
0 comments:
Post a Comment