I was wondering... what is considered the best practice to instantiate blank value objects? (in Java)
E.g. Assume we have some value object class Foo, that could be blank.
Would creating methods like these be a clean solution? (And perhaps adding in a "Blankable" interface or something).
interface Blankable {
public Foo blankInstance();
public boolean isBlank();
}
class Foo implements Blankable {
public Foo blankInstance();
public boolean isBlank();
}
Foo foo = something();
if (foo.isBlank()) // Tell the user
Or would something more simple like this be better?
class Foo {
public static Foo BLANK = /* Some constructor */;
}
Foo foo = something();
if (foo == Foo.BLANK) // Tell the user
I am leaning toward the first example, but I am still not sure if it is a widely accepted technique.
I feel a bit resistant to (but still open to) using the Guava Optional< T> class because it seems like a work-around solution in this circumstance.
Aucun commentaire:
Enregistrer un commentaire