简体   繁体   中英

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. But in the future I will need to add denoise_4, validation_four, etc.

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 . Simply place all your algorithms in a List<DenoiseAlgorithm> and run them one by one by iterating over that list.

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 pattern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM