What is it about great APIs that makes them great? I think that adhering to the "do one thing and do it well" mantra is a good sign and being is a good mapping to the problem domain is important, but what do great APIs have in common?
|
|
You have to be careful to avoid adding new vocabulary just for the sake of your API. My favorite APIs explain things to me in vocabulary I already understand. Along those lines: Don't add too many abstractions on top of what you're building on. Keep it simple.I already have to think about about half-a-dozen layers of abstraction. Dont make me think about extra layers. Don't give me too many new things to learn that won't add value to my end goal. For example, avoid using your own special file class that works differently then the language's file type just cause you think your way is better than the generally accepted way. Stick with the generally accepted way, at least in your interfaces, for better or for worse. Stick with concrete ideasFor example don't try to hide the fact that the "model" part of your MVC framework is a front end for a database. Take advantage of the well known vocabulary surrounding "databases". I know what foreign keys are. I know what rows and columns are. Talk to me in these terms. Don't abstract out essential knowledgeSimilar to working with concrete ideas. Don't hide the fact that we're dealing with files or databases or rows in databases. I know these things. If I'm dealing with a container, like a List, there's a good chance I need to know the algorithmic complexity of common operations. You can simplify that a lot by just telling me its a "linked list" or an "array". A huge set of ideas will suddenly be brought to bear on what you're doing and it'll all suddenly make sense. Don't create your own set of ideas that I have to learn when I'll already come with a rich and useful set of terminology to apply to the problem. Reduce the number of terms I need in my vocabularyIf I'm using your API to open an image file of any type, I shouldn't have to think about pngs vs gifs vs jpgs very much. You'll do that for me. Its your core competency, not mine. I have some vague understanding that you have some magic to do this for me. |
||||
|
|
|
A useful API has the following:
|
|||||||||||
|
|
Great APIs have great documentation. |
|||||
|
|
|||
|
|
|
This question is addressed in "Practical API Design: Confessions of a Java Framework Architect" by Jaroslav Tulach from the NetBeans team. |
|||
|
|
