In my Java (Spring Boot) app, I have the following pdf service that uses BrandService
:
Service:
public interface PDFService<T, S> {
String generatePdf(UUID uuid);
}
BrandServiceImpl:
@Service
@RequiredArgsConstructor
public class BrandPDFServiceImpl implements PDFService {
private final BrandService brandService;
public String generatePdf(UUID uuid) {
BrandDTO brandDTO = brandService.findByUuid(uuid);
// ...
}
}
Now I need to duplicate BrandPDFServiceImpl
as CookbookPDFServiceImpl
, and I can do this easily as shown below:
CookbookPDFServiceImpl:
@Service
@RequiredArgsConstructor
public class CookbookPDFServiceImpl implements PDFService {
private final CookbookService cookbookService;
public String generatePdf(UUID uuid) {
CookbookDTO cookbookDTO = cookbookService.findByUuid(uuid);
// ...
}
}
However, I am not sure if I should use Template Method
design pattern for the common generatePdf
method. So, in this scene, what is the most proper way?
Aucun commentaire:
Enregistrer un commentaire