对数据值执行元逻辑是反模式吗?
考虑一个对象
Person
firstName
lastName
有一项提案建议我们对没有姓氏的名人使用lastName =“__NOLASTNAME”。这似乎是一种反模式。它有名字吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它称为魔术字符串:
http://en.wikipedia.org/wiki/Magic_string
It's called Magic String:
http://en.wikipedia.org/wiki/Magic_string
我会说是的,这是一种反模式。姓名?嗯,“等待发生的灾难”怎么样?
使用此表的所有应用程序是否都知道
“__NOLASTNAME”
是一个特殊值?您有更多这些特殊价值观吗?还会有更多吗?
就像
"__NOLASTNAMEBUTNOCELEBRITYEITHER"
来表示跟踪者?或者也许
"__NONEOFTHEABOVE"
来表示公司?如果有人将自己的名字命名为
“__NOLASTNAME”
,会发生什么?他们会自动获得名人般的待遇吗?例如,可以使用名人桑拿浴室吗?顺便问一下,我在哪里报名?根据您建模的内容以及信息的使用方式,您可以通过多种不同的方式来解决它,例如拥有名人实体,或向 Person 添加属性 (type=person|stalker|celebrity) 或甚至标记 isCelebrity(true|false)。
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).