Khangharoth

September 28, 2009

Type Safety in Api’s

Filed under: Uncategorized — khangharoth @ 2:26 pm

As of now am working on a fairly big  project which intended to have impact on entire bank level architecture and should be in use for more than 10 yrs .We didn’t got number 10 yrs from any mathematical calculation but it was a way to convey the message, that return on this sort of project typically comes after 5-6 yrs.

So after knowing very well that their will be many systems using your System and for  fairly long lifesapn , How do you design you Api’s ?

This particular  system is supposed to be a Cluster on Distributed Grid and will give option to other Systems to get data from Cache rather than hitting RDBMS and going forward the plan is that all System just work on top of this grid and so for them no Db calls !!

Now this systems will have fairly big outward facing Api’s and question in our mind was how to design these sort of Api’s. One important aspect of this design analysis is

What level of type safety we should have ?

Although with introduction of Ruby etc in mainstream programming , java static type saftey is preety much under attack.But my experience suggest that if you have a project on which more than 10 people will code than this is really a very important aspect to see while choosing a language . And this can be seen in Java’s success in big server side projects.

Now coming back to the point , how important is Type Safety in you Api’s which are exposed to outside world(other than your team) ?

Well answer from my side is very much , don’t give user a chance to call your Api’s with Generic Arguments.So while designing you Api’s try to be as as type safe as possible .

  • Don’t take generic String as argument’s for everything and then do conversion’s .
  • It really difficult to find a usecase where a method takes a argument as Object or return’s a Object.
  • If you have such methods then examine them closely or this may be perfect case to show your Generics knowledge.

While pondering over this i came across this article and really enjoyed reading it ,as it reinforces the concept that your api’s should be type safe and this should happen at compile time.

Also its a good news that Criteria queries will be part of JPA 2.0 which i think was most missed feature in JPA especially when you have hibernate as persistence provider.

Blog at WordPress.com.