tags:

views:

26

answers:

2

I am developing a key value store abstraction layer, much like JDBC or ActiveRecord, and I would like to provide varying levels of API, such that at its most basic it is:

get Key
set Key, Value
exists Key
delete Key

However, I also want to provide another API which provides lower level details which can be used with CAP theorem datastores such as:

get Key, Number_of_nodes_to_read_from
set Key, Value, Number_of_nodes_to_write_to
exists Key, Number_of_nodes_to_check
delete Key, Number_of_nodes_to_check, timeout_in_milliseconds

: And to make things really complicated I would also like an API where value added things can be added such as map reducers, indexes, records with fields, searching.

Anyway, my question is whether I should make one huge list of functions, or should I split up the API, bearing in mind that I may wish to add to the API in the future.

Thanks

Zubair

Note: The original question I had is here:

http://stackoverflow.com/questions/2321650/is-this-api-too-simple

+1  A: 

In lieu of a long-winded answer, I strongly recommend that you watch the Google Techtalk entitled "How To Design A Good API and Why it Matters", since I believe it addresses your question.

My own recommendation would be to expose your API only through the builtin map or dictionary interface provided by the language, until such time as it becomes necessary to provide users with a higher level of control. If you expose too much from the outset, you will lock yourself into your particular implementation, which is completely contrary to the purpose of an API ... that is, to provide abstraction.

Michael Aaron Safyan
Yes, I agree. It was after watching that google tech talk a few weeks ago I decided to think about this carefully. I read Beautiful Code and Clean Code too, and very helpful
Zubair
+1  A: 

How about get Key, Map_of_params
The second param could be a simple Map of key-values.

Padmarag
Mmmmm, yes, I think this would be a very good way of doing it, much like Ruby does alot with Rails. Since I have a multi-language API are hashes used for arguments much in Java?
Zubair
Well I had seen this in the Heads First OOAD book. Normally you could also use a parameter object, but Map seems fine.
Padmarag
Have you used this in practice yourself? I ask because it would be useful to find how you found it in practice
Zubair
Not really. We generally use parameter object, since the exact parameters are known and we do not have public(external) API
Padmarag
Ok, thanks anyway.
Zubair