|
Professional Programmer
Join Date: Mar 2005
Posts: 343
Rep Power: 4 
|
An example,
Well okay taking your example and using it (since I don't really have code I can post right now)
A fairly simple database component that takes in a number of variables and stores them (name, address, phone number, etc etc), now I can have one method that takes in everything
public void StorePerson( string FirstName, string LastName, string Address1, string Address2, string City, string State, string Zip, string Country, int Age, bool Married, string areacode, string phone7 )
{
do stuff
}
but then the requirement is that you fill each of those variables, and say someone doesn't have an address2, then you have to use null instead, which for numerics gets somewhat harder since you can't use null, so you have to use 0 and if the field means something for 0, you need to define the 'null' value.
Alternative is to have many varients, a basic one that takes in the mandatory fields, and then others that each take in progressively more of the optional variables, the issue then becomes say address2 and city are variable, you could end up with
public void StorePerson( string FirstName, string LastName, string Address1, string Address2, string State, string Zip, string Country, int Age, bool Married, string areacode, string phone7 )
{
do stuff
}
public void StorePerson( string FirstName, string LastName, string Address1, string City, string State, string Zip, string Country, int Age, bool Married, string areacode, string phone7 )
{
do stuff
}
Which on a number of variables and types selection are in fact, the same method.
|