Is performing meta-logic on data values an anti-pattern?

111 views Asked by At

Consider an object

Person
   firstName
   lastName

There is a proposal that would suggest that we use lastName = "__NOLASTNAME" for a celebrity with no last name. This seems like an anti-pattern. Is there a name for it?

2

There are 2 answers

0
Mateusz On BEST ANSWER

It's called Magic String:

http://en.wikipedia.org/wiki/Magic_string

4
Ronnis On

I would say yes, it's an anti pattern. Name? Hmm, how about "Disaster Waiting to Happen"?

Do all applications that work with this table know that "__NOLASTNAME" is a special value?
Do you have more of those special values and will there be more of them?
Like "__NOLASTNAMEBUTNOCELEBRITYEITHER" to indicate a a stalker? Or maybe "__NONEOFTHEABOVE" to indicate a company?

What happens if somebody gives their name as "__NOLASTNAME"? Will they automatically get treated like a celebrity? Access to Celebrity Saunas for example? Where do I sign up by the way?

Depending on what it is that you model, and how you the information will be used, you can solve it in many different ways, such as having a Celebrity entity, or adding an attribute to Person (type=person|stalker|celebrity) or flag even isCelebrity(true|false).