sidhartha pani
sidhartha pani

Reputation: 663

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
}

Upvotes: 4

Views: 2344

Answers (1)

msagala25
msagala25

Reputation: 1806

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

Upvotes: 7

Related Questions