基于规则的设计
我会定期阅读一些离散状态,并对状态差异应用一些规则,我会报告一些错误。 规则可以及时更改。
解决此类问题的最佳实践是什么?
谢谢。
I will regularly read some discrete states, and applying some rules to differences in states I will report some errors. Rules can be changed in time.
What are best-practices to solve such a problem?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我首先想到的是 Gof 的 设计模式,称为 策略。
您可以在具体策略对象中对规则进行编码。
因此,您可以拥有一个随时间变化的特定具体策略对象。
但最好是更改具体策略对象以反映新规则,恕我直言。
维基百科链接有一个 C++ 示例。但如果您不熟悉设计模式和/或需要进一步解释,请询问。
What first comes to my mind is the Gof' Design Pattern called Strategy.
You encode your rules in the Concrete Strategy objects.
So you could have a particular Concrete Strategy object that is changing in time.
But best is to change of Concrete Strategy objects to reflect the new rule, IMHO.
The wikipedia link has an example in C++. But if you are new to design patterns and/or need further explanations about it, just ask.
除了策略模式之外,我还会使用单例模式。
一种可能的实现(尽管这是相当开放的,如果您想要一组灵活的规则,您应该使用另一个类作为“规则”实体。但是,这种方式更容易理解):
当然,这是标头的指示(s)。缺少实施文件。希望这有帮助。
I'd also use the singleton pattern, apart from the Strategy one.
One possible implementation (though this is quite open, if you want a flexible set of rules you shoud use another class for the "Rule" entity. However, this way it is simpler to understand):
Of course this is an indication of the header(s). The implementation files are missing. Hope this helps.