P
perkins45
So lets say I have this pretend function that compares a given serial
number against the one true serial VALID_SERIAL:
bool validateSerial(string serialNum)
{
if(serialNum == VALID_SERIAL)
return true;
else
return false;
}
I want to add a function that does the same thing, but will also pad
the given serialNum with a prefix of "0" if the original serialNum
does not check out. I was thinking I could change the original
function to something like:
bool validateSerial(string serialNum, bool padFlag = false)
{
if(!padFlag)
{
if(serialNum == VALID_SERIAL)
return true;
else
return false;
}
else
{
// padding functionality...unimportant for now
}
}
but that would seems ugly to have one function that should be really
be two. I could also overload it with a new function like
bool validateSerial(string serialNum, bool padFlag)
{
//padding functionality
}
but that function would not even use the padFlag variable.
Any suggestions on how I should organize these public functions from
an OO perspective?
Thanks
number against the one true serial VALID_SERIAL:
bool validateSerial(string serialNum)
{
if(serialNum == VALID_SERIAL)
return true;
else
return false;
}
I want to add a function that does the same thing, but will also pad
the given serialNum with a prefix of "0" if the original serialNum
does not check out. I was thinking I could change the original
function to something like:
bool validateSerial(string serialNum, bool padFlag = false)
{
if(!padFlag)
{
if(serialNum == VALID_SERIAL)
return true;
else
return false;
}
else
{
// padding functionality...unimportant for now
}
}
but that would seems ugly to have one function that should be really
be two. I could also overload it with a new function like
bool validateSerial(string serialNum, bool padFlag)
{
//padding functionality
}
but that function would not even use the padFlag variable.
Any suggestions on how I should organize these public functions from
an OO perspective?
Thanks