Help with design structure choice: Using classes or library of functions
Posted
by
roverred
on Programmers
See other posts from Programmers
or by roverred
Published on 2013-11-01T03:45:27Z
Indexed on
2013/11/01
4:15 UTC
Read the original article
Hit count: 206
design
|object-oriented
So I have GUI Class that will call another class called ImageProcessor
that contains a bunch functions that will perform image processing algorithms like edgeDetection, gaussianblur, contourfinding, contour map generations, etc.
The GUI passes an image to ImageProcessor
, which performs one of those algorithm on it and it returns the image back to the GUI to display. So essentially ImageProcessor
is a library of independent image processing functions right now.
It is called in the GUI like so
Image image = ImageProcessor.EdgeDetection(oldImage);
Some of the algorithms procedures require many functions, and some can be done in a single function or even one line.
All these functions for the algorithms jam packed into ImageProcessor can be pretty messy, and ImageProcessor doesn't sound it should be a library. So I was thinking about making every algorithm be a class with a shared interface say IAlgorithm.
Then I pass the IAlgorithm interface from the GUI to the ImageProcessor.
public interface IAlgorithm{
public Image Process();
}
public class ImageProcessor{
public Image Process(IAlgorithm TheAlgorithm){
return IAlgorithm.Process();
}
}
Calling in the GUI like so
Image image = ImageProcessor.Process(new EdgeDetection(oldImage));
I think it makes sense in an object point of view, but the problem is I'll end up with some classes that are just one function. What do you think is a better design, or are they both crap and you have a much better idea? Thanks!
© Programmers or respective owner