Reputation: 32331
I need an design here in my case . I am using a Third Party API for contacting a Database and getting the Data . The return type of this API can be of different types such as Array List , Enumeration , Hash Map depending upon the type of request made and finally We will construct a Generic Response Object based on that return type .
Now my question is that , what should be the design or the Design Pattern to be used in my case ??
Please help .
Thanks
Upvotes: 0
Views: 78
Reputation: 3986
For the first part, you need to isolate the third party database vendor API interaction into its own object so that the information related to third party API doesn't percolate elsewhere into the code. Use a DAO to ensure this and make sure all database related interaction is exposed as ordinary methods by this layer i.e nothing vendor specific.
For the second part, what do you intend to do with the returned object; probably iterate through them. So you should wrap them into an object, like the Response object that you have mentioned. The object which wraps the returned object should provide a standard/ consistent way of performing operations (example it could expose an Iterator on the wrapped object so the user can iterate in a return type agnostic way).
Upvotes: 1