Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some comments (not necessarily problems):</p> <ol> <li>The Date class is itself mutable so you are correctly copying it to protect immutability, but personally I prefer to convert to long in the constructor and return a new Date(longValue) in the getter.</li> <li>Both your getWhateverInstance() methods return DateBean which will necessitate casting, it might be an idea to change the interface to return the specific type instead.</li> <li>Having said all that I would be inclined to just have two classes one mutable and one immutable, sharing a common (i.e. get only) interface if appropriate. If you think there will be a lot of conversion back and forth then add a copy constructor to both classes.</li> <li>I prefer immutable classes to declare fields as <strong>final</strong> to make the compiler enforce immutability as well.</li> </ol> <p>e.g.</p> <pre><code>public interface DateBean { public Date getDate(); } public class ImmutableDate implements DateBean { private final long date; ImmutableDate(long date) { this.date = date; } ImmutableDate(Date date) { this(date.getTime()); } ImmutableDate(DateBean bean) { this(bean.getDate()); } public Date getDate() { return new Date(date); } } public class MutableDate implements DateBean { private long date; MutableDate() {} MutableDate(long date) { this.date = date; } MutableDate(Date date) { this(date.getTime()); } MutableDate(DateBean bean) { this(bean.getDate()); } public Date getDate() { return new Date(date); } public void setDate(Date date) { this.date = date.getTime(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload