Quantcast
Channel: How should I implements functions which are used for the same purpose when using strategy design pattern? - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 4

How should I implements functions which are used for the same purpose when using strategy design pattern?

$
0
0

First of all I am going to give you a brief explanation of what i am after doing. I want to write a program that applies filters to an image using a strategy design pattern. I have read some documentations about the pattern and decided to use it like this.

First I will create an Interface called FilterStrategy which has one method called applyFilter.

After that I create 2 different classes, lets call them BeautifulFilter and UglyFilter that implement the interface above.

Then I will write a context class which has a private member of FilterStrategy and a setter method for two different strategies. And lastly one more method in which i call the applyFilter

In main my function I create a FilterStrategy and set the filter for UglyFilter and call the function.

Here is what I am asking. BeautifulFilter and UglyFilter has many common methods such as read image, write image, convolution and display... and there also some methods that are used by only one of the filters above. Where am I supposed to implement these methods? Should I duplicate my code in both of the filter classes?


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images