0

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!

nmarques
  • 151
  • 12

2 Answers2

1

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.

Eric Stein
  • 13,209
  • 3
  • 37
  • 52
0

A precise answer to your question would require knowing the language you are using and/or the platform. Eric in his answer above is correct that wrapping the data inside one of you own class is one way to handle this. However, depending on the language, the details of the final implementation will vary and the amount of work required when adding possible return value type will also vary. In Java for example one way to handle this would be to return an heterogeneous container. Take a look at this thread: Type safe heterogeneous container pattern to store lists of items

Community
  • 1
  • 1