javarestamazon-s3api-designriak-cs

Class structure for client library


I need to make a couple of services that will talk to both Amazon S3 and Riak CS.

They will handle the same operations, e.g. retrieve images.

Due to them returning different objects, in S3's case an S3Object. Is the proper way to design this to have a different class for each without a common interface?

I've been thinking on how to apply a common interface to both, but the return type of the methods is what's causing me some issues, due to them being different. I might just be going wrong about this and probably should just separate them but I am hoping to get some clarification here.

Thanks all!


Solution

  • Typically, you do this by wrapping the responses from the various external services with your own classes that have a common interface. You also wrap the services themselves, so when you call your service wrappers they all return your wrapped data classes. You've then isolated all references to the external service into one package. This also makes it easy to add or remove services.