是什么使耦合“松散"?更好地编写松散耦合的代码吗? [英] What makes coupling "loose" and is it better to write my code loosely coupled?

查看:39
本文介绍了是什么使耦合“松散"?更好地编写松散耦合的代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
什么是松耦合"?请提供示例.

是什么使耦合变得松散",而编写我的松散耦合的代码会更好?

What makes coupling "loose" and is it better to write my code loosely coupled?

**请提供一些链接.

** please provide me with some links.

推荐答案

相关问题中有一些示例.

There are a few examples in the related question What is "loose coupling".

关于您的代码是否应该松散耦合,这取决于它正在实现的系统.

As to whether your code should be loosely coupled, that rather depends what the system it is implementing is.

例如,网络是松散耦合的-任何组件都通过相同的http界面,并且您可以在各个层中的任意位置将组件的实现和服务的提供者从硬件切换到应用程序.

For example, the web is loosely coupled - any component goes through the same http interface, and you can switch the implementations of components and providers of services willy-nilly anywhere in the layers from hardware to application.

另一方面,用于高性能图形卡的驱动程序与为其专门设计的硬件紧密耦合-其他任何事情,都会导致性能下降.鉴于操作系统和驱动程序之间的接口之间的耦合不太紧密(对于给定操作系统版本的所有驱动程序而言都是通用的),而应用程序代码和操作系统之间的接口通常不那么紧密地耦合在一起,也许符合长期存在的标准,例如OpenGL.

On the other hand, the driver for a high performance graphics card is tightly coupled to the hardware it is designed for - anything else, and you lose performance. Whereas the interface between the OS and the driver is less tightly coupled, being common to all drivers for a given OS version, and the interface between application code and the OS is often less tightly coupled again, perhaps conforming to a long lived standard such as OpenGL.

您的代码在这些极端之间的合适位置将确定哪种耦合程度合适.

Where your code fits between these extremes will determine what degree of coupling is appropriate.

这篇关于是什么使耦合“松散"?更好地编写松散耦合的代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆