0

If I would like to incorporate the JodaTime library into my MVC project. What would be the best way to write the setter/getter methods for my bean? I've currently tied my local variables to the LocalDate object in JodaTime, but this is probably not a good idea (if others use this bean, they may not be able to use the Joda library). Should I make my local variables java.util.Date objects? If so, would I then convert these java.util.Date objects to JodaTime's LocalDate in the Controller or the Service Layer (my assumption would be the service layer as that's where my business logic currently resides)?

public class Survey {
    LocalDate startdate;
    LocalDate enddate;

    public void setStartDate(LocalDate startDate) {
        this.startDate = startDate;
    }

    public LocalDate getStartDate() {
         return this.startDate;
    }
}
tshepang
  • 12,111
  • 21
  • 91
  • 136
Robert
  • 1,638
  • 7
  • 34
  • 45

1 Answers1

1

(if others use this bean, they may not be able to use the Joda library)

Do you have any reason to believe at the moment that they wouldn't be able to?

If this is an internal project, presumably you should be able to find out whether or not they can take Joda Time.

I would strongly urge you to stick with Joda Time end-to-end if at all possible. Every conversion introduces another potential error both in terms of the coding and (more importantly) the human understanding of what data you're trying to represent.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • No I have no reason to believe that. I was just trying to be proactive :). So since the type can stay as a LocalDate at what layer would I perform my formatting to display? In the Controller, the setter method or service layer? – Robert Aug 21 '12 at 16:02
  • @Robert: I'd expect that to be in the view, given that it's presentation logic, isn't it? But I don't have enough experience of MVC to give too much concrete advice on it... – Jon Skeet Aug 21 '12 at 16:03