Linking objects together

  • Thread starter Thread starter james.tsao
  • Start date Start date
J

james.tsao

Let's say I have two classes, DNA, SocialSecurityNumber, and
Fingerprint.
There is a one-to-one-to-one relationship between the classes but no
"wired" link between them.
Suppose I want a hashtable, the key being an int that i maintain and
the value being something that holds all three aforementioned objects.
the way i've been doing this is to create a simple class (or struct)
that holds the three:

class DNASSNFPContainer
{
private DNA dna;
private SocialSecurityNumber ssn;
private FingerPrint fp;

public DNASSNFPContainer(DNA dna, SocialSecurityNumber ssn,
FingerPrint fp)
{
this.dna = dna;
this.ssn = ssn;
this.fp = fp;
}

public DNA Dna
{
get
{
return dna;
}
}

public SocialSecurityNumber Ssn
{
get
{
return ssn;
}
}

public FingerPrint Fp
{
get
{
return fp;
}
}
}


this approach feels clunky. instinct tells me that there's a more
elegant way but i can't come up with anything.

thanks in advance.
JT
 
(e-mail address removed) wrote in
Let's say I have two classes, DNA, SocialSecurityNumber, and
Fingerprint.
There is a one-to-one-to-one relationship between the classes
but no "wired" link between them.
Suppose I want a hashtable, the key being an int that i maintain
and the value being something that holds all three
aforementioned objects. the way i've been doing this is to
create a simple class (or struct) that holds the three:

<code snipped>

this approach feels clunky. instinct tells me that there's a
more elegant way but i can't come up with anything.

James,

IMO, the most natural approach would be to put those three data
members in a Person type, along with all of the other kinds of data
that can be used to describe a person.

Otherwise, you could put them in a separate type as you have done,
but change the name to something more general, like Identifiers or
Descriptors.
 
Back
Top