保持评论对象状态的最佳方法是什么?
我有一些网络应用程序可以放置在外部网站上。该应用程序是一个用于评论的小部件,例如 disqus (disqus.com)。
每个评论都是一个实体对象,其中包含以下字段:“作者”、“正文”、“时间”等。 除了这些字段之外,注释对象还具有名称为“active”的字段 即:
@Entity
class Comment {
private User author;
private String body;
//... and a lot of many other attributes
private boolean active;
}
“活动”字段用于分隔活动评论和已删除评论。 如果“active”== false,则评论被删除,如果不是,则评论处于活动状态。
很快我将推出一个允许预先审核评论的功能。 即用户发布评论,但在管理员尚未批准之前,评论仍然不活跃。
所以问题是最好的制作方法是什么?
我看到两种方法:
1)将“active”字段从布尔值更改为int并保留评论状态,
例如:0 - 预审核,1 - 活动(已批准),-1已删除,-2未批准可能是一些其他事情...
2)保留“活动”布尔字段并添加状态附加字段
I have some web application for placement on external sites. This application is a widget for comments like disqus (disqus.com).
Each comment it's a entity object with fields: "author", "body", "time" and etc.
In additional to these fields comment object has field with name "active"
That is:
@Entity
class Comment {
private User author;
private String body;
//... and a lot of many other attributes
private boolean active;
}
The "active" field used to separate active and deleted comments.
If "active" == false the comment is deleted, if no it's active.
Very soon I will introduce a functional which allows to pre-moderation of comments.
That is user publishes a comment but until administrator has not approved it, comment still not active.
So the question is what's the best way to make it?
I see two ways:
1) Change "active" field from boolean to int and keep the status of comment,
for instance: 0 - pre-moderation, 1 - active (approved), -1 deleted, -2 not approved may be some thing else...
2) Leave "active" boolean field and added additional field for status
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么是
int
- 为什么不是enum
?编辑:另外,尽量不要将您的
enum
分散到各处。使用 Comment 类作为稳健模型,为isActive()
或isPending()
添加函数 - 无论您使用一个还是两个字段,或者使用枚举或一个 int,这是一个实现细节。隐藏那个嘶嘶声,哟。Why an
int
- why not anenum
?Edit: Also, try not to scatter your
enum
all over the place. Use your Comment class as a robust model, add functions forisActive()
orisPending()
-- whether you use one field or two, or whether you use an enum or an int, that's an implementation detail. Hide that shizzle, yo.