B
Bill Woodruff
Consider a class that maintains two private instances of Generic Lists, one
of type string, one of type int :
class PolyClass
{
private List<string> listOStrings;
private List<int> listOInts;
public polyClass
{
listOStrings = new List<string>();
listOInts = new List<int>;
}
}
Now you define an Add operator that takes a string and an int as its
parameters, and an overload for the Add operator that takes an int and a
string as its parameters. You add a Get operator that takes an int as its
input parameter and returns the string in the listOStrings List at the same
index location as the int in the listOInts. You create an over-ride for the
Get operator that takes a sting as input parameter and returns the matching
int.
So now someone can use your class to add items using either the string-frst,
or the int-first flavours of Add. And use the Get operator similarly. Yes,
all of this compiles and works fine.
My question is : does this type of coding in a way "violate" the strongly
typed "basis" of C#; i.e., is it a "bad" practice, a "tolerable" but unwise
practice, or ?
thanks, Bill
of type string, one of type int :
class PolyClass
{
private List<string> listOStrings;
private List<int> listOInts;
public polyClass
{
listOStrings = new List<string>();
listOInts = new List<int>;
}
}
Now you define an Add operator that takes a string and an int as its
parameters, and an overload for the Add operator that takes an int and a
string as its parameters. You add a Get operator that takes an int as its
input parameter and returns the string in the listOStrings List at the same
index location as the int in the listOInts. You create an over-ride for the
Get operator that takes a sting as input parameter and returns the matching
int.
So now someone can use your class to add items using either the string-frst,
or the int-first flavours of Add. And use the Get operator similarly. Yes,
all of this compiles and works fine.
My question is : does this type of coding in a way "violate" the strongly
typed "basis" of C#; i.e., is it a "bad" practice, a "tolerable" but unwise
practice, or ?
thanks, Bill