多层/多层系统等于紧耦合系统吗?

发布于 2024-08-17 21:55:16 字数 283 浏览 5 评论 0原文

我发现每当我创建一个/多个层时,我都必须在一层到另一层之间进行转换,这是否意味着它是一个紧密耦合的系统?如果我要更改业务逻辑,删除数据库中的字段等,我是否必须更改从数据库层到客户端前端的所有层?

例如,一个Web服务公开一个“数据契约”对象,并将其转换为中间层的一些“业务对象”,然后将其转换为数据层中适当的“ORM对象”。而客户端调用Web服务,将数据契约转换为一些模型对象等等……

既然中间有这么多的转换,那么Web服务如何设计成松耦合呢?只是我的想法,如果有人可以分享他/她的意见那就太好了。

谢谢

I find that whenever I create a layer/tier, I have to translate between one layer to the other, does that mean it is a tightly coupled system? If I was to change a business logic, remove a field in the database, etc, I would have to change ALL layers from the database layer to the client front end?

E.g. A web service that exposes a "data contract" object, and converts it to some "business objects" in the middle layer, then converts it to the appropriate "ORM object" in the data layer. And the client calling the web service, converts the datacontract to some model objects, etc...

Since there are so many translations in between, how can web services be designed to be loosely coupled? Just getting my head around it, if someone can share his/her opinions it would be great.

Thanks

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

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

发布评论

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

评论(1

幸福丶如此 2024-08-24 21:55:16

转换或映射与松散耦合是正交的,尽管有些相关。

  • 如果从具体类型映射到具体类型,则映射是紧密耦合的
  • 如果从抽象类型映射到具体类型,反之亦然,则映射是松散耦合

的换句话说,松耦合与接口编程的概念相关,而不是与映射相关。

如果应用程序中的各层通过具体类型相互通信,则它是紧密耦合的。在这种情况下,分层并没有提供太多价值,您还不如构建一个整体应用程序。

另一方面,如果一个层通过接口与其他层通信,这些层将是松散耦合的,但通常仍然需要映射。

Translation or mapping is orthogonal, although somewhat related, to loose coupling.

  • If you map from concrete type to concrete type the mapping is tightly coupled
  • If you map from abstract type to concrete type or the other way around, the mapping is loosely coupled

In other words, loose coupling is related to the concept of programming to interfaces - not to mapping.

If layers in an application communicate with each other through concrete types, it's tightly coupled. In such a case, layering doesn't provide much value, and you might as well have built a monolithic application.

On the other hand, if a layer communicates with other layers through interfaces the layers will be loosely coupled, but mapping is often still required.

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