The Artima Developer Community
Sponsored Link

Design Forum
Design Pattern suggestion: Neutral Element instead NULL

1 reply on 1 page. Most recent reply: Dec 24, 2009 2:34 PM by Krisztian Sinka

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Jan Kechel

Posts: 1
Nickname: jkechel
Registered: Dec, 2009

Design Pattern suggestion: Neutral Element instead NULL Posted: Dec 19, 2009 4:26 PM
Reply to this message Reply
Advertisement
Hi everybody,

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 multiplikation 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? Intersting approach or not?

best regards,

Jan Kechel


Krisztian Sinka

Posts: 30
Nickname: skrisz
Registered: Mar, 2009

Re: Design Pattern suggestion: Neutral Element instead NULL Posted: Dec 24, 2009 2:34 PM
Reply to this message Reply
Hi,

What if you leave the NULL as it is and create “interpreter” function in your application that can be used in the problem at hand. For example

InterpretAdd(inputValue)

would just return inputValue if it is not NULL and zero if inputValue is NULL.

Then you could have your all interpreter functions for many different cases.

Flat View: This topic has 1 reply on 1 page
Topic: Technology Selection for a web application Previous Topic   Next Topic Topic: N97 BAD Software Design

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use