views:

65

answers:

2

I'm considering using Joda Time.
I'm wondering if I should pay attention of what type of object my Interfaces are returning.
Returning Joda Objects from my interface signature on the service layer means that every module that use it will have be dependent on jodaTime instead of the common Date API.
Are you passing Joda objects around your App modules or do you write wrappers in specific part of your app?

+2  A: 

What is the alternative ? Transforming jodaTime objects into infamous Calendar/Date objects ?

You chose to get rid of these objects and that's a good decision. Now, if you let other layers use the java date API, they'll go into the kind of bugs and non-sensical behaviours you got rid of by using jodaTime.

I think you should do your users a favor and let them use jodaTime.

Of course it's a design decision that'll add in their code a dependency to jodaTime, but I don't find it questionnable, as you chose jodaTime to write less and better code, and so should they.

Riduidel
+2  A: 

In the beginning, only return the most suitable type (Joda Objects in this case).

If you learn that someone has a problem with that (which probably won't happen too often), either add a converter method to the interface (so you have, say, getTime() and now getJavaTime() or getTimeInMillis()).

Or add a general purpose helper method which takes an Object (you can treat an unknown instance as Object anywhere in the code without having to import the actual Joda classes) and returns a plain Java object (java.util.Date).

Aaron Digulla