oop を使用して、ユーザー生成データのサイトを構築し始めています。
私のクラスからはさまざまな種類のデータが得られます。データベースからデータのリストを取得する関数と、それらのリストから 1 つの項目を選択する関数があります。例えば
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
さて、これらの機能を整理するには、クラスをどのように設定すればよいでしょうか。それらをすべて同じクラスに入れるか、記事からコメントを分離するか、記事/コメントのリストを取得する関数から単一の記事/コメントを取得する関数を分離する必要があります。後でコメントを許可するものをサイトに追加する可能性があるため、すべてのコメント機能を他の機能から分離することを考えていました. また、「ローカル」関数はすべて、数学を実行する同じ関数を使用するため、それらをグループ化するか、単に継承を使用する必要があります...何か提案はありますか???
おっと、私は次のようなユーザークラスを持っています... private $user = array();
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 関数のパラメーターとして user_data を設定する必要がありますか?