Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between POJO (Plain Old Java Object) and DTO (Data Transfer Object)?

I cannot find difference between them. Does anyone know how to differentiate them?

like image 979
d1ck50n Avatar asked Sep 15 '09 05:09

d1ck50n


3 Answers

POJO or "Plain Old Java Object" is a name used to describe "ordinary" Java objects, as opposed to EJBs (originally) or anything considered "heavy" with dependencies on other technologies.

DTO or "Data Transfer Object" is an object for... well... transferring data, usually between your "business" classes and persistence layer. It typically is a behavior-less class much like a C-style struct. They are an outdated concept.

like image 157
SingleShot Avatar answered Oct 29 '22 03:10

SingleShot


A POJO is just a simple Java object, the acronym is used to emphasize that it really is nothing special.

A DTO is a Data Transfer Object which is used to encapsulate data that is transferred over a connection between layers or subsystems. See the wikipedia article, it's also a Core J2EE pattern (http://www.oracle.com/technetwork/java/transferobject-139757.html).

http://en.wikipedia.org/wiki/Data_transfer_object

like image 36
Jon Avatar answered Oct 29 '22 01:10

Jon


All DTOs are POJOs, but not all POJOs are DTOs. An example of POJO that is not a DTO is a business class that contains state and behavior (business logic).

like image 8
Paulo Merson Avatar answered Oct 29 '22 02:10

Paulo Merson