jeudi 5 mai 2022

Using Template Method (Design Pattern) for differentiate fields

I have been using a Create Request as shown below and needed to implement an Update Request with some fields non-required.

@Data
public class CreateRequest extends BaseRequest {

    @NotEmpty
    private String token;

    @NotEmpty
    private String secret;
}
@Data
public class UpdateRequest extends BaseRequest {

    private String token;

    private String secret;
}

There are some relations and interfaces that should be used by both request. I think of using Template Design pattern by keeping the shared fields of these requests. Is that suitable for this scenario? Or, what would you suggest?

Aucun commentaire:

Enregistrer un commentaire