与单独模板的接口和实现

发布于 2025-01-28 16:20:06 字数 637 浏览 4 评论 0原文

我有一个带有几个实现类的Java接口。每个实现类都需要自己的关联(子)模板。在运行时,我将实现我的接口的对象的集合(列表)添加到我的st。我如何在适当的模板呈现的列表中将每个对象都有的每个对象?

示例代码:

public interface foo {...}
public class bar implements foo {...}
public class baz implements foo {...}

我想为接口FOO拥有一个顶级ST,每个混凝土/实现类都有其自己的ST,如下所示,

foo.st
bar.st
baz.st

我想通过list< foo>,包含barbaz实例的混合物,并将foo st拨打调用适当的子网板(bar > baz ,取决于列表的每个元素的子类型)。

我想我可以创建一个map< string/ *模板名称 */,foo/ * bar或baz */>,但是感觉就像这样,我正在泄露我的事实'm在我的数据模型设计中使用StringTemplate。

有什么建议吗?

I have a Java interface with several implementing classes. Each implementation class needs its own associated (sub)template. At runtime I add a collection (List) of objects implementing my interface to my ST. How can I have each object in that list rendered by the appropriate template?

Example code:

public interface foo {...}
public class bar implements foo {...}
public class baz implements foo {...}

I would like to have a top-level ST for the interface foo, and each concrete/implementing class has its own ST as follows,

foo.st
bar.st
baz.st

I would like to pass a List<foo>, which contains a mix of bar and baz instances, to the foo ST and have the foo ST call the appropriate sub-template (bar or baz, depending on the subtype) for each element of the list.

I suppose I could create a Map<String /* template name */, foo /* either bar or baz */>, but it feels like by doing so I'm leaking the fact that I'm using StringTemplate into my data model design.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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