Why do DAOs have separate create and update methods?
I'm looking at a couple of designs for DAO interfaces. One has a single update()
method, whi开发者_运维技巧le the other has separate create()
and update()
methods.
Assuming that it's possible to do something along the lines of 'insert otherwise update', what's the benefit of a separate create()
method? Is there something to do with concurrency lurking there?
Thanks in advance for your help.
Cheers, Ross
I use two seperate methods when creating DAO's simply for Clarity and Explicitness.
If there is a single Update method and somebody passes in an existing object, it will be updated. But what if the person really wanted to Create a new object and the fact that it already existed is an error?
With a single Update method, there's really no way for anybody to tell what EXACTLY is going on behind the scenes.
精彩评论