-
Nulls and business objects.
For the longest time I have struggled to come up with a clean way to deal
with Null values when creating business objects that read data from a
database. In my particular case, I program in VB, VB 6 to be more specific.
And if there is one thing that I wish, is that VB had variables such as
Integers with the capability to not only receive numerical integer values
but also Null values. We would finally have a nice clean one to one
representation of the data from the database and the object model.
I currently use tricks such as Variants, assign default values such as a
person's age being -1, etc. Needless to say this is annoying and just one
more way to introduce bugs etc. Why can't there be a variable that does
this. Somebody suggested one being out there but I have not been able to
find it.
How do you guys deal with this issue? Does languages like Delphi allow you
to do this?
PS: There are some cases where I believe that using Null values is a great
idea, I don't want to get into a philosophical debate here, so not allowing
Nulls is not the right solution for me.
-
Re: Nulls and business objects.
I have always used variants to represent numeric values in my state-rich
components.
Another Architect I know had a "mirror" property that would represent if the
value was null or not. In all the code dealing with these properties, the
property get would first check the value of the "mirror" property. If it
was true, then the property was null. I don't like this method, since it
bypasses what built-in null handling capabilities VB does have.
--
Brian G. Rice
Entier Solutions Inc.
"Rene" <rahome@niia.net> wrote in message news:3a3d8ab4@news.devx.com...
> For the longest time I have struggled to come up with a clean way to deal
> with Null values when creating business objects that read data from a
> database. In my particular case, I program in VB, VB 6 to be more
specific.
> And if there is one thing that I wish, is that VB had variables such as
> Integers with the capability to not only receive numerical integer values
> but also Null values. We would finally have a nice clean one to one
> representation of the data from the database and the object model.
>
> I currently use tricks such as Variants, assign default values such as a
> person's age being -1, etc. Needless to say this is annoying and just one
> more way to introduce bugs etc. Why can't there be a variable that does
> this. Somebody suggested one being out there but I have not been able to
> find it.
>
> How do you guys deal with this issue? Does languages like Delphi allow you
> to do this?
>
> PS: There are some cases where I believe that using Null values is a great
> idea, I don't want to get into a philosophical debate here, so not
allowing
> Nulls is not the right solution for me.
>
>
-
Re: Nulls and business objects.
Rene,
There's an article in VBPJ June 2000 I think.
"Brian G. Rice" <bgrice@entier.org> wrote:
>Another Architect I know had a "mirror" property that would >represent if
the value was null or not. In all the code >dealing with these properties,
the property get would first >check the value of the "mirror" property.
If it
>was true, then the property was null. I don't like this >method, since
it bypasses what built-in null handling >capabilities VB does have.
Brian,
You'd hate what I've done then.
I've got a string called Nulls which is internal to the
object. The string has a character for each property and uses
'1' or '0' to indicate if that property is Null or not.
You can build the string when the record is read in.
I had considered using bits to store the 1s and 0s
so I could use Bitwise operators, but the string thing seems to
make more sense to people who are learning how to use the architecture.
It has serious problems like having to remember to set
the approperiate character of the string to 0 if you assign
a non null property. A bit like the mirror properties you
mentioned.
The only other thing of interest is that the Nulls string
is actually maintained within a Class called CMetaClass. Every
object exposes a CMetaClass through a property called Meta.
Meta is initialized during the class initialize of the host
class e.g. CEmployee.
It provides Methods for checking if a given property is Null:
x = obj_Employee.Meta.PropertyIsNull("Grade")
or for indicating if a property is Null
x = obj_Employee.Meta.PropertySetNull("Grade", False)
Meta does a lot of other stuff as well but that's how I handle
Nulls. It started as a temporary solution until I figured out
what I really wanted to do, and it grew into this monster.
-Richard
-
Re: Nulls and business objects.
Looks like I am not the only one going trough this ****. I wonder why this
issue has not been taken seriously by the programming languages makers and
why they have not fixed this problem.
Just in case you are curious to know, my latest solution in dealing with
nulls has been to assign a particular value on every variable that will
represent Null. For example:
NullValueForDate = 0
NullValueForByte = 255
NullValueForInteger = -32768
NullValueForLong = -2147483648
NullValueForSingle = -3.402823E+38
Etc.
The only pain in the butt with this one is that the client has to check for
the value every time it reads it from the object model. The other pain is
that the object model also has to check the value before its saves the data
to either save the actual value or a Null.
In reality its not that bad, I simply created a function that does this so
its not that big of a deal it is only a dirty implementation, but the
cleanest way so far.
Thanks for the help.
-
Re: Nulls and business objects.
What's wrong with using Variants? It support Nulls and the memory penalty is
not that big considered the usual amount of memory used today
If you need to map a value to/from Null, let you database access classes do
that.
/Thomas
"Rene" <rahome@niia.net> wrote in message news:3a3d8ab4@news.devx.com...
> For the longest time I have struggled to come up with a clean way to deal
> with Null values when creating business objects that read data from a
> database. In my particular case, I program in VB, VB 6 to be more
specific.
> And if there is one thing that I wish, is that VB had variables such as
> Integers with the capability to not only receive numerical integer values
> but also Null values. We would finally have a nice clean one to one
> representation of the data from the database and the object model.
>
> I currently use tricks such as Variants, assign default values such as a
> person's age being -1, etc. Needless to say this is annoying and just one
> more way to introduce bugs etc. Why can't there be a variable that does
> this. Somebody suggested one being out there but I have not been able to
> find it.
>
> How do you guys deal with this issue? Does languages like Delphi allow you
> to do this?
>
> PS: There are some cases where I believe that using Null values is a great
> idea, I don't want to get into a philosophical debate here, so not
allowing
> Nulls is not the right solution for me.
>
>
-
Re: Nulls and business objects.
"Thomas Eyde" <thomas.eyde@bdc.no> wrote:
>What's wrong with using Variants? It support Nulls and the >memory penalty
is not that big considered the usual amount of >memory used today
Well you'd end up needing a Variant for almost everything.
we won't argue about whether or not Nulls should be allowed,
but if they are then it's safe to assume that the potential exists for pretty
much any field to be Null.
I use variants but I try to use them sparingly.
Anyway, in a .Net world we don't have variants anymore.
Although I presume .Net datatypes will have the ability to
store Null since they are all actually classes.
-Richard
-
Re: Nulls and business objects.
"Rene" <rahome@niia.net> wrote:
> For the longest time I have struggled to come up with a clean way to deal
>with Null values when creating business objects that read data from a
>database. In my particular case, I program in VB, VB 6 to be more specific.
>And if there is one thing that I wish, is that VB had variables such as
>Integers with the capability to not only receive numerical integer values
>but also Null values. We would finally have a nice clean one to one
>representation of the data from the database and the object model.
We use variants to store the values internally to a business object. The
business object exposes a null boolean property (ContainsNull) which can
be checked for those class clients who don't want to eat the null or have
to do special state handling themselves.
HTH,
Matthew Cromer
-
Re: Nulls and business objects.
"Richard Dalton" . wrote:
>
>"Thomas Eyde" <thomas.eyde@bdc.no> wrote:
>>What's wrong with using Variants? It support Nulls and the >memory penalty
>is not that big considered the usual amount of >memory used today
>
>Well you'd end up needing a Variant for almost everything.
>we won't argue about whether or not Nulls should be allowed,
>but if they are then it's safe to assume that the potential exists for pretty
>much any field to be Null.
>
>I use variants but I try to use them sparingly.
>
>Anyway, in a .Net world we don't have variants anymore.
>Although I presume .Net datatypes will have the ability to
>store Null since they are all actually classes.
>
>-Richard
So you folks here are all jumping on board the .NET express? Am I the only
one who bailed for Java? Of course, .NET is just another flavor of Java
anyway. . . ;-)
Matthew Cromer
-
Re: Nulls and business objects.
"Matthew Cromer" <matthew@sdaconsulting.com> wrote:
>So you folks here are all jumping on board the .NET express? >Am I the
only one who bailed for Java? Of course, .NET is just >another flavor of
Java anyway. . . ;-)
I'm convinced .Net is a virus that infects every discussion
thread regardless of the opening topic. 
Let's not get into a .Net for and a against on this one.
But for the record, It looks like I'll be using .Net
at work about 1 to 2 years after it ships. Until then I'm
stuck/sticking with VB6.0. Although I'll be using it at
home much sooner. (Soon as my super computer arives)
Right now the biggest focus of my attention is architecture
and trying to find out just how much you can abstract
architecture away from the technical details.
In theory .Net should be irrelevent from an architecture
perpective, but of course theory and reality are different
things.
-Richard
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|