December 19th, 2009, 06:38 PM
Design Pattern suggestion: Neutral Element instead NULL
i had the idea that this might be an interesting approach especially in handling numerical database null values. -> Tell the app that numerical null values (this are e.g. null values in integer, float, decimal, .. database columns) should be handled as neutral elements regarding to any mathematical operations (e.g. for addition this would be a 0 (zero), for multiplication a 1 (one) and so on).
Of course this is not always what you want, so there are still the cases where you want an exception to be thrown (so take it as null value) or to have it some default value (e.g. 0 _or_ 1 or any other value of course).
I guess there would be needed some more input, especially on how to apply this to string values (are there neutral strings? Maybe that is just the same as the empty string? Whats the neutral string for numerical null values -> probably the empty string as well.
What do you think? Interesting approach or not?
but more important: How could I implement this the best way? Maybe by extending the 'Null Value Pattern' to behave like this, (maybe NeutralNull) ?
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!