Skip to content

Instantly share code, notes, and snippets.

@nh2
Created July 28, 2012 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nh2/3195264 to your computer and use it in GitHub Desktop.
Save nh2/3195264 to your computer and use it in GitHub Desktop.
StaticPipeline in Java (not working)
package staticpipeline;
class Image implements ProvidesOriginalImage {
@Override
public Image getOriginalImage() {
return null;
}
}
class FaceLocation implements ProvidesFaceLocation {
@Override
public EyeLocation getFaceLocation() {
return null;
}
}
class EyeLocation implements ProvidesEyeLocation {
@Override
public EyeLocation getEyeLocation() {
return null;
}
}
interface ProvidesOriginalImage {
Image getOriginalImage();
}
interface ProvidesProcessedImage {
Image getProcessedImage();
}
interface ProvidesFaceLocation {
EyeLocation getFaceLocation();
}
interface ProvidesEyeLocation {
EyeLocation getEyeLocation();
}
interface FaceDetectionResult extends ProvidesOriginalImage,
ProvidesProcessedImage, ProvidesFaceLocation {
}
interface EyeDetectionInput extends ProvidesOriginalImage,
ProvidesProcessedImage, ProvidesFaceLocation {
}
interface EyeDetectionResult extends ProvidesOriginalImage,
ProvidesProcessedImage, ProvidesEyeLocation {
}
class FaceDetector {
FaceDetectionResult detectFace(ProvidesOriginalImage i) {
return null;
}
}
class EyeDetector {
EyeDetectionResult detectEyes(EyeDetectionInput i) {
return null;
}
}
public class StaticPipeline {
@SuppressWarnings("unused")
public static void main(String[] args) {
Image i = new Image();
FaceDetector fd = new FaceDetector();
EyeDetector ed = new EyeDetector();
/*
* And finally, this doesn't work, because FaceDetectionResult is not
* the same as EyeDetectionInput for Java, although they extend exactly
* the same interfaces.
*
* ("The method detectEyes(EyeDetectionInput) in the type EyeDetector is
* not applicable for the arguments (FaceDetectionResult)")
*/
// ed.detectEyes(fd.detectFace(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment