Designing a better API?


  1. What are the best practices and patterns to be followed for designing APIs?
  2. How to achieve implementation hiding the best way (C++/Java)?
  3. Designing APIs which are generic in nature?
  4. Any reference books/links which guide with neat examples to beginners?
9/14/2009 3:22:35 PM

Accepted Answer

12/2/2014 5:31:49 PM

I'm not sure I have a great answer for all of your individual questions there but I think I do have a good answer for the very first one.

Try to use it before it is ever written. By that I mean, write unit tests for the code as if it really did exist. Write some of the code that will be using the API before you've even written one line of the API. As you try to use it you'll quickly see what works and what doesn't work in the design you had in mind and you'll be quick to change it to match its actual use because you haven't yet written any of the actual code.

There's never any friction to changing something if you haven't committed any of it to code, but the moment you do, there is often some measure of reluctance to do so.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow