I would create an »ImageProcesssor« (or whatever name suits your project) and a configuration object ProcessConfiguration, which holds all necessary parameters.
ImageProcessor p = new ImageProcessor();
ProcessConfiguration config = new processConfiguration().setTranslateX(100)
.setTranslateY(100)
.setRotationAngle(45);
p.process(image, config);
Inside the imageprocessor you encapsulate the whole process behind one mehtod process()
public class ImageProcessor {
public Image process(Image i, ProcessConfiguration c){
Image processedImage=i.getCopy();
shift(processedImage, c);
rotate(processedImage, c);
return processedImage;
}
private void rotate(Image i, ProcessConfiguration c) {
//rotate
}
private void shift(Image i, ProcessConfiguration c) {
//shift
}
}
This method calls the transformational methods in the correct order shift()
, rotate()
.
Each method gets appropriate parameters from the passed ProcessConfiguration.
public class ProcessConfiguration {
private int translateX;
private int rotationAngle;
public int getRotationAngle() {
return rotationAngle;
}
public ProcessConfiguration setRotationAngle(int rotationAngle){
this.rotationAngle=rotationAngle;
return this;
}
public int getTranslateY() {
return translateY;
}
public ProcessConfiguration setTranslateY(int translateY) {
this.translateY = translateY;
return this;
}
public int getTranslateX() {
return translateX;
}
public ProcessConfiguration setTranslateX(int translateX) {
this.translateX = translateX;
return this;
}
private int translateY;
}
I used fluid interfaces
public ProcessConfiguration setRotationAngle(int rotationAngle){
this.rotationAngle=rotationAngle;
return this;
}
which allows nifty initialization (as seen above).
The obvious advantage, encapsulating necessary parameters in one object.
Your method signatures become readable:
private void shift(Image i, ProcessConfiguration c)
It is about shifting an image and detailed parameters are somehow configured.
Alternatively, you could create a ProcessingPipeline:
public class ProcessingPipeLine {
Image i;
public ProcessingPipeLine(Image i){
this.i=i;
};
public ProcessingPipeLine shift(Coordinates c){
shiftImage(c);
return this;
}
public ProcessingPipeLine rotate(int a){
rotateImage(a);
return this;
}
public Image getResultingImage(){
return i;
}
private void rotateImage(int angle) {
//shift
}
private void shiftImage(Coordinates c) {
//shift
}
}
A method call to a method processImage
would instantiate such a pipeline and make transparent what and in which order is done: shift, rotate
public Image processImage(Image i, ProcessConfiguration c){
Image processedImage=i.getCopy();
processedImage=new ProcessingPipeLine(processedImage)
.shift(c.getCoordinates())
.rotate(c.getRotationAngle())
.getResultingImage();
return processedImage;
}