可以替换if语句的设计模式 [英] Design patterns that can replace if statements

查看:697
本文介绍了可以替换if语句的设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用越来越复杂,主要有3个流,必须基于3种之一进行处理。许多这些功能彼此重叠。



所以目前的代码完全是if-else语句,它全部搞砸了,没有组织。如何使一个模式,使3个流明确分开,但利用可重用性的力量。



请提供一些想法,这是一个MVC应用程序,我们需要使用jaxb技术生产和使用Web服务。



可能您可以将应用程序视为单个对象作为需要实现不同策略的输入基于运行时值。

解决方案

在长时间之后,我找到诸如 drools 之类的开源规则引擎框架是符合我要求的绝佳选择。


Our application is getting complex, it has mainly 3 flow and have to process based on one of the 3 type. Many of these functionalities overlap each other.

So currently code is fully of if-else statements, it is all messed up and not organised. How to make a pattern so that 3 flows are clearly separated from each other but making use of power of re-usability.

Please provide some thoughts, this is a MVC application, where we need to produce and consume web servicees using jaxb technology.

May be you can view the application as a single object as input on which different strategies needs to be implemented based on runtime value.

解决方案

After loong time I find opensource rule engine frameworks like "drools" is a great alternative to fit my requirement.

这篇关于可以替换if语句的设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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