[英]Strategy pattern and iterator on all algorithms
I have a list of algorithms that I want to run on an image for denoise it. 我有一个要在图像上进行去噪的算法列表。 I have several different algorithms for denoising my pics.
我使用几种不同的算法对图片进行降噪处理。 Say I have denoise_1 and denoise_2 and denoise_3.
假设我有denoise_1和denoise_2和denoise_3。 But in the future I will need to add denoise_4, validation_four, etc.
但是将来我将需要添加denoise_4,validation_four等。
I need ALL of the denoise to run on the picture, even the new ones when they get added. 我需要所有降噪才能在图片上运行,即使添加了新的降噪效果也是如此。
In addition : if I add another algorithm I must notify the system. 另外:如果添加其他算法,则必须通知系统。
I am thinking about using strategy and observer patterns, but I have not found an acceptable solution. 我正在考虑使用策略和观察者模式,但没有找到可接受的解决方案。
Is this the right way?? 这是正确的方法吗?
I apologize if for opening a new thread, I found a similar thread but I did not understand the solution. 如果打开新线程,我发现一个类似的线程,但我不了解解决方案,我深感抱歉。
Yes strategy is fine: 是的,策略很好:
Let all denoise Algorithm implement a common Interface. 让所有降噪算法实现一个公共接口。
Say all your algorithms implement the same DenoiseAlgorithm
. 假设您所有的算法都实现相同的
DenoiseAlgorithm
。 Simply place all your algorithms in a List<DenoiseAlgorithm>
and run them one by one by iterating over that list. 只需将所有算法放在
List<DenoiseAlgorithm>
并通过遍历该列表逐一运行它们即可。
If the list is global, adding new algorithm (at the beginning or the end, you decide) has global effect on the whole system. 如果列表是全局的,则添加新算法(由您决定是在开头还是结尾)会对整个系统产生全局影响。
Also consider chain-of-responsibility pattern. 还考虑责任链模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.