与单独模板的接口和实现
我有一个带有几个实现类的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>
,包含bar
和baz
实例的混合物,并将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 技术交流群。

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