Question

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;
    }
}
Was it helpful?

Solution

(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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top