如果我访问数据库一次而不是十次,哪种设计模式适用?
我正在查看一段代码,它将所有不同的查询数据包装在一个对象中。有没有适用于这种场景的设计模式?
I am looking at a piece of code which wraps all disparate query data in a single object. Is there a design pattern that applies to this scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这确实不符合模式。
即使不同的数据也必须有一些共同点,并且在单个数据库调用中拥有这些共同点可以被认为是良好的编程。
当然,如果以后可能需要分发数据或在并行调用中完成数据(通常存储过程是顺序的,因此让客户端并行触发多个数据并等待所有数据完成通常会更快),这样的架构可能是被认为是不成熟的优化。
That really doesn't qualify as a pattern.
Even disparate data must have something in common and having that in a single database call could be considered good programming.
Of course, if it's possible the data later needs to be distributed or done in parallel calls (typically stored procedures are sequential, so having a client trigger several in parallel and wait for all to complete can often be quicker), such an architecture might be considered a premature optimization.
我不太确定你在说什么......但我将其称为工厂 - 那么工厂的实现可以对如何填充其成员做出优化选择。 (大概是通过减少数据库调用或您能想出的任何其他技巧)
I'm not really sure what you are getting at... but I would call this a FACTORY - then the implementation of the factory could make optimization choices about how to poulate its members. (presumably by fewer database calls or whatever other trick you can come up with)