I\'ve seen a lot of questions related to mapping DTOs to Domain Objects, but I didn\'t feel they answered my question. I\'ve used many methods before and have my own opinio
Why not we can do like this?
class UserDTO {
}
class AdminDTO {
}
class DomainObject {
// attributes
public DomainObject(DTO dto) {
this.dto = dto;
}
// methods
public function isActive() {
return (this.dto.getStatus() == 'ACTIVE')
}
public function isModeratorAdmin() {
return (this.dto.getAdminRole() == 'moderator')
}
}
userdto = new UserDTO();
userdto.setStatus('ACTIVE');
obj = new DomainObject(userdto)
if(obj.isActive()) {
//print active
}
admindto = new AdminDTO();
admindto.setAdminRole('moderator');
obj = new DomainObject(admindto)
if(obj.isModeratorAdmin()) {
//print some thing
}
@FrederikPrijck (or) someone: Please suggest. In the above example DomainObject is depends on DTO. By this way i can avoid the code to do mapping the dto <--> domainobject.
or DomainObject class can extends the DTO class?