抽象三层应用程序的数据层 (DAL)

发布于 2024-09-19 20:23:02 字数 343 浏览 8 评论 0原文

作为我上一个问题的延续,(请参阅https://stackoverflow.com/ questions/3737848/creating-a-loosely- Coupled-scalable-software-architecture

有人建议也抽象 DAL,就像我从三层项目的表示层抽象 BLL 一样。关于如何执行此操作有什么建议吗?我是否还需要在 BLL 和 DAL 之间建立一个工厂?我需要你们的意见……谢谢。

As continuation to my previous question, (see https://stackoverflow.com/questions/3737848/creating-a-loosely-coupled-scalable-software-architecture

Someone suggests to also Abstract the DAL like I abstracted the BLL from the Presentation Layer on my three tier project. Any suggestion on how to do this? Do I also need a factory between the BLL and the DAL? I need your input guys.. thanks.

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

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

发布评论

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

评论(1

栩栩如生 2024-09-26 20:23:02

有趣的是——在对表示层进行抽象之前,我会在 BL 和 DAL 之间进行抽象。

你的其他问题中使用的方法似乎是合理的 - 你为什么不重复使用它呢?

  • 是的,你需要一家工厂;但您可以将其包含在公共类/程序集中,并让它仅返回一个对象,然后您可以在返回时对其进行强制转换 - 即:在 BL 中调用它的位置。
  • (为了完整性:)使用 Activator.CreateInstance() (正如您在其他问题中使用的那样)是正确的方法。
  • 对于 DAL,我倾向于使用存储在配置中的值(作为传递到工厂的参数);经常更改 DAL 实现并不常见 - 所以配置对我来说效果很好。
  • 在设计 BL 和 DAL 之间的合约/抽象时,请遵守接口隔离原则 (ISP) -如果做得正确,您将能够同时混合搭配不同的物理 DAL 实现。
  • 如果您将 DTO 和工厂保留在一个公共程序集中(可能是同一个程序集),那么很容易通过 BL 和各种 DAL 实现重用它们 - 需要注意,您将此公共类保留为尽可能没有依赖性。如果您这样做,您将能够添加/更新 DAL 实现,而无需重新编译和重新部署整个系统。

Interesting - I'd put abstraction between the BL and DAL way before I'd do that for the presentation layer.

The approach used in your other question seems reasonable - why don't you just reuse that?

  • Yes you need a factory; but you can include this in a common class / assembly and have it just return a object, which you can then cast as it's returned - i.e: at the point in the BL where it's being called.
  • (for completeness:) using Activator.CreateInstance() (as you've used in your other question) is the right way to go.
  • For DAL I tend to use values stored in the config (as arguments to pass into the factory); it's not common to change the DAL implementation that often - so config works well for me.
  • Observe the Interface Segregation Principle (ISP) when designing the contractr / abstraction between the BL and DAL - if you do it right you'll be able to mix-and-match different physical DAL implementations at once.
  • If you keep the DTO's and factory in a common assembly (possibly the same one) then it's easy to re-use them with the BL and various DAL implementation - with the caveat that you keep this common class as devoid of dependancies as possble. If you do this you'll be able to add / udpate DAL implemenations without re-compiling and re-deploying the whole system.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文