薄API背后的包装配置信息是什么意思?
在阅读务实的程序员
时,作者建议我们在薄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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论