Is performing meta-logic on data values an anti-pattern?
Consider an object
Pers开发者_运维知识库on
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?
It's called Magic String:
http://en.wikipedia.org/wiki/Magic_string
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).
精彩评论