模板方法模式应用程序
我已经实施了模板方法设计模式来以这种方式处理不同类型的电子邮件的生成:
public abstract class TemplateBuilder {
public buildEmail(Map<String,Object> emailObjects) {
// do something here
}
}
我被迫通过词典,让我们来调用email obobjects
,因为每个扩展TemplateMailBuilder 具有方法
buildemail
的不同签名。通过这种方式,我可以从地图中检索,这是我需要构建特定电子邮件的特定对象。我检索的每个对象都是我在代码库中使用的特定类的实例,可用于创建电子邮件。
有什么方法可以概括这一点并避免将地图传递给模板方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论