d1ck50n
d1ck50n

Reputation: 1331

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?

Upvotes: 30

Views: 30899

Answers (8)

Paulo Merson
Paulo Merson

Reputation: 14495

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).

Upvotes: 8

Hardzsi
Hardzsi

Reputation: 41

I could understand the difference between POJO and DTO from this sentence of DTO's wiki:

DTOs are simple objects that should not contain any business logic but may contain serialization and deserialization mechanisms for transferring data over the wire.

Also, DTO is perfectly visualized and described in detail in Martin Fowler's Catalog of Patterns of Enterprise Application Architecture

Upvotes: 1

Jonathan Holloway
Jonathan Holloway

Reputation: 63714

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

Upvotes: 12

user3016087
user3016087

Reputation: 69

DTO is pojo, but pojo is not dto, because pojo can have more behavior but DTO just basically no behavior

Oracle document has clear description.

Upvotes: 5

Abhijeet Kashnia
Abhijeet Kashnia

Reputation: 12900

A POJO can have behavior. The book POJOs in Action details use of POJOS for application development. DTOs are data containers that help transfer data from one layer to another. DTOs aren't supposed to contain any behavior.

Upvotes: 3

user10398
user10398

Reputation: 480

DTO (Data transfer object) : Is a Core J2EE design pattern used for transferring data within the system.DTO Pattern


POJO (Plain Old Java Object) : It is just an acronym people use for suggesting that is a simple java object (which nowadays is heavily annotated for doing some meaning full work).

DTO Pattern
J2EE Pattern Catalog

Upvotes: 5

SingleShot
SingleShot

Reputation: 19131

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.

Upvotes: 20

Noon Silk
Noon Silk

Reputation: 55112

POJO = Plain Old Java Object

DTO = Data Transfer Object

-- Edit

Well, this is assuming you don't know what the acronyms mean. A Pojo is just an object that is free from any sort of inheritance chain. A DTO exists in your data model, so probably follows a strict chain relating it to a given entity.

Upvotes: -3

Related Questions