mercredi 13 janvier 2021

Which design patter we can use in case of two class having common fields so that we don't need to create new Class?

In a spring boot application, I return a UserResponseDTO in the first api as below

public class UserReponseDTO{
  private Long Id,
  private String field1,
  private String field2,
  private String field3,
  private String field4,
  private String field5,
  private String field6,
  
//setters and getters...
}

But as per the requirement of a second API, I need to return response DTO having 2 more fields.

public class NewReponseDTO{
  private Long Id,
  private String field1,
  private String field2,
  private String field3,
  private String field4,
  private String field5,
  private String field6,
 
  //new fields
  private String fields7,
  private String fields8
 
 //setters and getters...
}

Which design pattern can be used so that I can add new fields on runtime in UserResponseDTO instead of creating new responseDTO

Aucun commentaire:

Enregistrer un commentaire