sidhartha pani sidhartha pani - 1 year ago 83
Java Question

Data transfer object class can contain other objects?

I just wanted to know DTO class contain another objects or not. Please tell me the below code is valid DTO class or not?

class Address implements Serializable{

private String city;
private String location


class EmployeeDTO implements Serializable{
private String name;
private int age;
private Address address;
//setters and getters

Answer Source

DTO - Data transfer objects are just data containers which are used to transport data between layers and tiers. It mainly contains attributes. You can even use public attributes without getters and setters. Data transfer objects do not contain any business logic.

Yes I think that they are valid DTO's but wihtout business logic. The main purpose of DTO is they hold values to be used in other layers of the design of the system.

A plus to remember, DTO's have no other behavior other than the getters and setters of the attributes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download