If DTOs use inheritance or composition

In SOA, if multiple DTO classes have multiple fields that repeat. It is better to use composition or inheritance so that there is no repetition or just use one DTO class that encapsulates all fields. As my DTO classes grow, I see many duplicate field names, and the Sonar report is a crying bird. What is the best approach (or alternative).

eg.

public class DocDto{
private Long id;
private String name;
private String docType
}

public class DocReviewDto{
private Long id;
private String name;
private String status;
private String comment;
}
+4
source share
1 answer

" DTO" . . . , . . . "DocReview" , DTO, . Bleagh! , DTO : "Doc" "DocReview". , "" . ; .

, , Identifier, DTO .

public class Identifier {
  long id; // should be a 'String', actually
  String name;
}

public class Doc {
  private Identifier identifier;
  private String docType
}

public class DocReview {
  private Identifier identifier;
  private String status;
  private String comment;
}

, Identifier , . .

: "Dto" ( "DTO" ) , .

+9

All Articles