模板方法模式应用程序

发布于 2025-02-07 02:38:53 字数 462 浏览 2 评论 0原文

我已经实施了模板方法设计模式来以这种方式处理不同类型的电子邮件的生成:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文