比方說,我有一個用戶對象進行使用ORM CRUD操作:ORM中的對象是否包含CRUD以外的操作?
//Create a new User
$user = new User();
$user->name = "John Smith";
$user->age = 30;
$user->email = '[email protected];
$user->save();
Similiar操作也將是avaliable對Read
,Update
和Delete
。
但對於這樣的情況下:
deleteAllUsers() //delete all users
getAllUsers() //get all users
promoteUser() //change the user's 'rank' (not permissions) within a website
addReputationPoints() //give the user x amount of reputation points
是將這些類型的操作進入User
類?如果不是,他們應該去哪裏?我是否應該有一個名爲UserManager
的課程來處理這些操作?
您可能對這篇文章感興趣:http://stackoverflow.com/questions/8010764/best-practices-hibernate-persistence-code-inside-the-entity-itself –