是否有一种设计模式可用于创建和填充从 xml 模式生成的复杂对象层次结构?

发布于 2024-09-19 07:16:26 字数 224 浏览 1 评论 0原文

我有一个从 xml 模式生成的复合对象,我需要用数据库中的数据填充该对象。

生成的代码不会强制执行架构关于所需元素、最大出现次数等的规则。我想创建一个类(或类集合)来帮助填充复合对象并确保其序列化时生成的 xml 将验证反对模式。

我研究了各种创建设计模式,构建器模式似乎适用于此,但我从未使用过它,我只是不确定。

构建器模式是最好的方法还是我偏离了轨道?有更好的方法来解决这个问题吗?

I have a composite object that was generated from an xml schema that I need to populate with data from a database.

The generated code doesn't enforce the schema's rules regarding required elements, max occurances, etc. I'd like to create a class (or collection of classes) to help fill in the composite object and ensure when its serialized the resulting xml will validate against the schema.

I've looked into the various creational design patterns and the Builder Pattern seems like it might work for this but having never used it I'm just not sure.

Is the Builder pattern the best way or am I off track? Is there a better way to go about this?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-柠檬树下少年和吉他 2024-09-26 07:16:26

简短的回答是肯定的,构建器听起来是最合适的方式。

但现实是,这里并没有真正的错误。任何复合材料、建造者、工厂都可以达到目的。我会从类似构建器(或者可能是工厂,但这是个人喜好)之类的东西开始,也许它会演变成一个稍微修改的模式,具体取决于您的用例。

模式只是起点,仅此而已:)

the short answer is yes, builder sounds like the most appropriate way to go with.

but the reality is that there's no REAL wrong way here. anything composite, builder, factory will all do the trick. I would start with something like builder (or maybe factory, but thats a personal preference) and maybe it'll evolve into a slightly modified pattern, depending on your use case.

patterns are just starting points, nothing more :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文