我開始使用oop來構建用戶生成數據的網站。我應該如何設置我的課程?
有不同類型的數據從我的班來了。 我有從數據庫中獲取數據列表的函數,並且只能從這些列表中選擇一個項目。 例如
function Get_Article($aid); //Gets an article
function Get_Users_Articles($uid); //Gets a multidemsional array of the users
//articles
function Get_Latest_Articles(); //Self explanatory by now
function Get_Local_Articles($zip); //Gets articles written by local users
function Get_Local_Users($zip); //Gets all local users
function Get_All_Article_Comments($aid); //Gets a multidimensional array of the
//comments written for an article
function Get_Article_Comment($cid); //Gets a single article comment
現在,我應該怎麼設置我的班來組織這些功能。 我應該把它們全部放在同一個班級,還是應該將文章中的評論分開,或者將檢索單篇文章/評論的功能與檢索文章/評論列表的功能分開。之後我可能會在網站上添加更多可以發表評論的內容,所以我只是想將其他評論功能與所有評論功能分開。此外,「本地」功能都使用執行數學的相同功能,所以我應該將它們組合在一起,或者只是使用繼承......任何建議?
雖然在OOP的問題,我有一個用戶類,看起來像...... 私人$ USER =陣列();
public function Get_User_Data($uid){
//get user data from database
return $this->user;
}
public function Set_User_Data($user_array){
$this->user = $user_array;
}
public function Add_User(){
//INSERT data from $this->user into the database
}
現在,任何人都不會看到什麼毛病這個樣子,順便居多,我應該設置中的用戶數據作爲ADD_USER函數中的參數,而不是插入的成員變量?