I was
reading a nice book about OOP techniques in Java. One of the concepts that
stuck out, to me, was the notion of "Design by Contract".
Basically, this means that a service (UDF, in my example) expects certain
input and returns expected output. The client (any calling code, in my
example) is required, by "contract" to supply correct information to the service
in order to get the desired results.
This
is easily understood. Now, my question comes with "how smart" should a UDF
be, yet still not try to do too much.
My
example is displaying a Social Security Number on a page. I may need to
output it in two different manners:
Normal: 123-45-6789
Masked: xxx-xx-6789
Now,
we all know that SSNs are nine-digit numbers.
QUESTION 1:
What
should happen if I pass a number that is not nine digits? Should it throw
an error or just return the passed value back to the page? Look at it in
both contexts of normal, formatted, SSN output as well as the masked SSN
output.
QUESTION 2:
Should
my UDFs prepend leading zeros to the beginning of any number that is less than
nine-digits? Or, should that have been done prior to the UDF
usage?
One
solution is to have the UDF do a lot of code in itself, but then, it would limit
its usage later on. The other solution is to create multiple, smaller UDFs
that do only a single task, but then that would require more UDF
nesting.
Thanks
M!ke
