Fri 30 Jan 2004
java.lang.String + wrong hands = textbook Anti-Pattern
Posted by dkaz under Java
It’s 1:33 AM and I’m about to catch some Z’s, but this Software Craftsman post
deserves a bit of bile.
There are very few things in life that I dislike more than a constructor
overloaded with Strings. This snippet of code from the post is absolutely
ridiculous:
public void createUser(String username,
String firstName,
String lastName,
boolean canCallerEditEmailAddress,
String emailAddress,
String addressLine1,
String addressLine2,
String addressLine3,
String addressLine4,
String addressLine5,
String phoneNumber,
String mobileNumber,
…) {
How about defining/using Name, PhoneNumber, Address and Email classes?
How can one possibly trust a phone number field of type String?
Why would you create a class called UserDataProvider instead (filled w/Strings)?
Is it just that I’m too damn sleepy to “get it”?
Another thing that eats at me is the validation inside of the createUser()
method. Are we planning to copy n’ paste it to the updateUser() method?
And don’t get me started on the CreateUserUseCaseEventHandlerForMassUpload.
Like I said - I’m too damn sleepy.

January 30th, 2004 at 4:26 pm
Hi,
All of the criticisms you make can be dealt with, but I too am tired. So I’ll just ask how you would code a use case so it can be used by a struts action and an Excel file? We can compare notes.
Cheers,
Mike.
January 31st, 2004 at 3:19 am
Hi,
I tried to reply to your criticisms in my blog (its an update at the bottom of the original post). Let me know what you think.
Cheers,
Mike.
January 31st, 2004 at 11:28 am
Mike -
I’m happy to see you address my concerns.
You’re a standup craftsman.