Written by Manuel Fernández Sánchez de la Blanca

martes, 17 de agosto de 2010

Don't break the oath.

When designing a distributable API, even if it is going to be distributed only inside you company, you must take special care on the public interface. The public interface is the entry point to the API, it says what can and cannot be done and which result the user can expect in case she provides appropriate input. It's a contract, an oath between you, the API developer, and the users.

The public interface should never be changed, except for adding new methods. If you change a public method's signature or, even worse, delete a public method, every source code using the API will break when updating it, and a lot of developers will dream about you and all your family.

So, what can you do if you detect a flaw in you API public interface? Well, the first thing should be keeping that public interface to the minimum; don't make a method public nor protected if you can avoid it; that way, you will have fewer things to worry about later. The second thing is: don't change a public method signature. You should mark it as deprecated and override it. If overriding is not possible, make a new method, but never never never do change the original one.

Be a developer of your word, don't break your oaths.

No hay comentarios:

Publicar un comentario