I am creating a class that is supposed to upload files to many a S3 Bucket with a presignedUrl. For now, I just have to upload files to a S3 Bucket. But in the future, i will have to upload files in others systems.
public interface uploader {
public void upload(String presignedUrl, InputStream inputStream) throws Exception;
}
My concern is the first parameter String presignedUrl and this : throws Exception
I think it is too specific and i dont think my futur implementations will fit this interface.
How can i design my interface to be less specific ?
I simplified like this :
public interface uploader {
public void upload(InputStream inputStream) throws Exception;
}
But now, i dont know how to get my presigendUrl
Your interface is not too specific. It has only single method (aka functional interface) - by definition smallest and most composable abstraction. You will easily create new implementation in future.
But
throws Exceptionis too generic. There are 3 ways to change it:RuntimeExceptioninstead of just generic checkedException.UploadExceptionextended from RuntimeException.Couple more tips:
Uploader, notuploader). It is Java convention.uploadmethod arguments insead ofString presignedUrl, InputStream inputStream.