I am working on an application which allows its users to apply different filters on an image that they upload. However, there is another requirement that needs to be fulfilled here. The application should allow the user to apply several filters on top of each other with a cumulative effect on the original image. Is there a design pattern that I can use to implement this? I have come up with the following two approaches which could be used to implement this design:
- Composite pattern: Have a
Filter
interface which is implemented by the variousConcreteFilter
classes and define a new classCompositeFilter
which collectsFilter
instances. - Decorator pattern with no concrete components: Have a
Filter
abstract class that contains a reference to an object ofFilter
itself which is extended by the variousConcreteFilter
classes (which are the decorators in this case).
The first option seems more appropriate to me as I'm not sure that the second method satisfies the intent of a Decorator pattern: adding additional responsibilities to (enhancing) a single component dynamically. What are potential uses and drawbacks for each approach and which one can be used to satisfy the requirement?
Thanks.