0

I have implemented the template method design pattern to handle the generation of different types of emails in this way:

public abstract class TemplateBuilder {
    
     public buildEmail(Map<String,Object> emailObjects) {
            // do something here
     }
}

I was forced to pass a dictionary, let's call emailObjects like this, because each concrete class that extends TemplateEmailBuilder has a different signature of the method buildEmail. In this way I can retrieve from the map, the specific objects that I need to build a specific email. Each object I retrieve is an instance of a specific class I use in my code base, useful to create an email.

Is there any way to generalize this and to avoid passing a Map to the template method?

FrMan
  • 31
  • 8

0 Answers0