java - Should I return null from or apply the "null object" pattern to a function returning a Date? -


let's have function returns date:

date myfunc(parama, paramb){    //conditionally return date? } 

is appropriate return null function? seems ugly because forces clients check null.

the "null object" pattern implementation pattern addresses concern.
i'm not huge fan of null object pattern, yes, makes sense return list, if empty, rather return null.
however, in java, null date 1 cleared , has year 1970.

what best implementation pattern here?

the null object pattern not trying do. pattern creating object no functionality in it's implementation can pass given function requires object not being null. example nullprogressmonitor in eclipse, empty implementation of iprogressmonitor.

if return "null" date, 1970, clients still need check if it's "null" seeing if it's 1970. , if don't, misbehaviour happen. however, if return null, code fail fast, , they'll know should check null. also, 1970 could valid date.

you should document method may return null, , that's it.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -