哪些设计模式可以应用到配置设置问题? [英] Which design patterns can be applied to the configuration settings problem?

查看:506
本文介绍了哪些设计模式可以应用到配置设置问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在管理可配置设置的大型和复杂软件产品中,成为一个主要的痛苦。我看到的问题的两种方法是:

In large and complex software products managing configurable settings becomes a major pain. Two approaches I've seen to the problem are:


  • 让系统中的每个组件从配置文件或注册表设置加载自己的配置。

  • 有一个设置加载器类,用于加载所有可配置的系统设置,并让每个组件为其设置查询设置加载器。

这些方法都让我感到不适。

These approaches both feel wrong to me.

有没有可用于简化问题的设计模式?可能会利用依赖注入技术。

Are there any design patterns that could be used to simplify the problem? Maybe something that would take advantage of the dependency injection technique.

推荐答案

我更喜欢创建一个用于设置查询,加载和保存的界面。通过使用依赖注入,我可以将它注入到需要它的每个组件中。

I prefer to create an interface for setting query, loading, and saving. By using dependency injection, I can inject this into each component that requires it.

这允许在替换配置策略方面的灵活性,工作。我喜欢这个单一的全局设置加载器(您的选项2),特别是因为我可以覆盖单个组件的配置机制,如果我绝对需要这样做。

This allows flexibility in terms of replacing the configuration strategy, and gives a common base for everything to work from. I prefer this to a single, global "settings loader" (your option 2), especially since I can override the configuration mechanism for a single component if I absolutely need to do so.

这篇关于哪些设计模式可以应用到配置设置问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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