I have this class containing two constructors with different signatures but they do the same thing:
public Person(Dictionary dictionary, string someString)
: base(dictionary, someString)
{
base.GetProperty("FirstName");
base.GetProperty("LastName");
}
public Person(Dictionary dictionary, string[] someStringArray)
: base(dictionary, someStringArray)
{
base.GetProperty("FirstName");
base.GetProperty("LastName");
}
The type of the second parameter in each of these constructors determines the behavior of the 'GetProperty' method.
I've read about casting
and the bad behaviors of it, but would it be appropriate to do something like this:
public Person(Dictionary dictionary, Object something)
{
}
and then cast something
to either a string
or string[]
depending on whichever is appropriate?
public Person(Dictionary dct, string[] something)
. Simpler, better for the client. – radarbob Oct 13 '13 at 2:11string[]
and if itsstring
just pickstring[0]
But the behavior between processingstring
andstring[]
are different, also the determination ofstring
andstring[]
is based elsewhere. The object itself does not determine if the parameter is astring
orstring[]
. I guess this is very vague. Im trying to add in a better example. – Rhs Oct 14 '13 at 13:12string[0]
is not the same thing/object/property asstring
in the other contractor, yes? How about optional parameters:public Person(Dictionary dict, string[] otherStuff, string Fname = null)
. – radarbob Oct 14 '13 at 21:50