开发者

Blog Application: should i embed the comment logic in the main blog entry class?

i am trying to write a blog application with CodeIgniter just for practice and using php (of course)

i just wanted to ask that which approach should i choose?

i am planning to write a Blog class with the basic following functions: Insert(), Update(开发者_运维问答), Read(), Delete()

now i want to ask if i should add the comment logic in the main Blog class? Such as InsertComment(), UpdateComment() and so on.

Or should i separate it in another class? i am confused because both are inter related and a comment will only be made on a Blog entry.


Each database entity should have it's own class. Plus, you can add comments to a lot more than blog posts. Articles, Events, Profiles, etc.. could all make use of that class. You could even add comments to comments.

You may only be planning on use the comment class for blogs - but apps change - and one day you might be needing comments on something else...


There is no one right answer to this one, it's pretty much a choice best left to the developer.

I will say this though, do you foresee that there may ever be some other feature you may add in the future that you may want to give your visitors the ability to comment on? If so, then the extra work done now to implement comments in their own class could potentially save you a lot of work later as you'll already have a comment module that, if well designed, will require little or no modification to allow use with your new feature.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜