构建器模式的真实示例
我想看看 Builder 模式是如何在现实世界的应用程序/API 中使用的。我找到的例子都是披萨、蛋糕、汽车等等(加上 GoF 书中的解析器示例)。
您能否告诉我这个模式在现实世界的应用程序/API 中的一些用法,最好是来自 C++、.NET 或 PHP 的世界(因为这些是我熟悉的语言)。
谢谢。
I would like to see how is Builder pattern used in real world applications/APIs. The examples I found are all pizzas, cakes, cars et cetera (plus the parser example from the GoF book).
Could you please tell me about some usages of this patten in real-world applications/APIs, preferably from the world of C++, .NET or PHP (as those are the languages I'm familiar with).
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新:我最近遇到了一个更好的例子(imo)。查看 Quartz 调度程序包中的 JobBuilder 和 TriggerBuilder 实现:http://quartz-scheduler.org/ api/2.1.5/
另外,当我有时间时,只是为了好玩/练习,我尝试用 java 编写所有 GoF 模式的示例。就在最近,我使用了 Builder 模式来轻松生成不同类型的站点地图(google 站点地图 vs、html 站点地图等)。代码是用java编写的,但你可能有用: https://github.com/dparoulek/java-koans/tree/master/src/main/java/com/upgradingdave/koans/builder
好问题,我有兴趣看看还有更现代的例子。
Update: I recently came across an even better example (imo). Checkout the JobBuilder and TriggerBuilder implementations in the Quartz scheduler package: http://quartz-scheduler.org/api/2.1.5/
Also, when I have time, just for fun/practice, I try to write examples of all GoF patterns in java. Just recently, I used the Builder pattern to make it easy to generate different types of Sitemaps (google site map vs, html site map, etc). The code is in java, but you might be useful: https://github.com/dparoulek/java-koans/tree/master/src/main/java/com/upgradingdave/koans/builder
Good question, I'd be interested in seeing more modern examples too.
构建器模式在构建 Json 对象时在 javax.json.Json 和 javax.json.JsonBuilder 类中使用。
很好的解释位于 http://www.programcreek .com/java-api-examples/index.php?api=javax.json.JsonObjectBuilder 并查看其 官方文档。
Builder pattern is used in
javax.json.Json
andjavax.json.JsonBuilder
classes while building Json objects.Good explanation is at http://www.programcreek.com/java-api-examples/index.php?api=javax.json.JsonObjectBuilder and also check out its official documentation.
实际上,一个非常好的现实示例是 Active Record QueryBuilder 示例。
您可以深入研究 Laravel Eloquent 模块并检查那些查询构建器类...
它的外观的快速示例:
Actually a very good real-life example is Active Record QueryBuilder example.
You can dig into the Laravel Eloquent module and check those Query builder classes...
A quick example of how it could look: