6. Date expressed as an Immutable Value.

Listing 6. Date expressed as an Immutable Value.


public final class Date ...
{
    public Date(Year year, Month month, int day)
    {
        this.year  = year.getValue();
        this.month = month;
        this.day   = day;
    }
    public int getYear() { return year; }
    public Month getMonth() { return month; }
    public int getDayInMonth() { return day; }
    ...
    private final int year, day;
    private final Month month;
}

About the Author

Kevlin Henney is a Principal Technologist with QA Training in the UK.