薄API背后的包装配置信息是什么意思?

发布于 2025-01-29 07:56:52 字数 409 浏览 1 评论 0原文

在阅读务实的程序员时,作者建议我们在薄API背后包装配置信息,因为它将其解除了配置表示的详细信息。

关于配置的书的报价。

通常,这种数据结构是全球化的,这种想法是,这使得代码的任何部分更容易获得其所持值。 我们更喜欢您不这样做。而是包裹(薄)API背后的配置信息。这将您的代码与配置表示的详细信息相关。

我不确定如何将配置表示的详细信息分解。例如,如果我有一个存储配置值的JavaScript对象,则客户端可以通过对象访问配置值。在对象内部包装此配置值不会在客户端中调用类似config。

由于配置对象通常表示为数据结构(即json喜欢),因此包装配置信息在薄API背后如何导致解耦?

On reading Pragmatic Programmer, the authors recommend that we wrap configuration information behind a thin API as it decouples the details of the representation of the configuration.

Quote from the book about Configuration.

Commonly, this data structure is made global, the thinking being that this makes it easier for any part of the code to get to the values it holds.
We prefer that you don't do that. Instead wrap the configuration information behind a (thin) API. This decouples your code from the details of the representation of the configuration.

I am not sure how that decouples the details of the representation of the configuration. For example, If I have a javascript object that stores a configuration value, the client could access the configuration value via object.<someConfigKey>. Wouldn't wrapping this configuration value inside an object result in the client calling something like config.<getSomeConfigKey>() ?

Since configuration objects are usually represented as a data structure (I.e json like), how does wrapping configuration information behind a thin API result in decoupling ?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文