OOPinion Question<

liunx

Guest
Hey All,
not really a problem..more of a matter of oppinion question...I have several(lets just use as a conservative example...4-5...number increasing as new code is added) classes resembling the following structure:


class News
{
var $db;
var $sessions;
var $template;
var $users;
var $InputParser;
var $OutputParser;
function News()
{
/* create references to db,sessions,users,InputParser,OutputParser classes previously initialized in GLOBAL array */

}
function RetError($errors)
{
/* display error msg with $errors content as the value
}
function Add()
{


if($this->users->AccessFromUsername('NewsAdd') == '0')
{
/* return access denied error */
}

else
{
if($_POST["Submit"])
{
/* run addslashes and such on variables,insert into db,return success msg or error msg */
}
else
{
/* return addition form template */
}

}



}
function Del()
{
if($this->users->AccessFromUsername('NewsDel') == '0')
{
/* return access denied error */
}
else
{
if($_GET["did"])
{
/* if access is valid,delete the entry and display success msg */
}
else
{
/* query database,return result of news posts,set value of delete admin,return template(display 'delete news' options) */
}


}

}
function Show()
{
/* query database,set value of template,return template(display news posts,atchual code left in to provide an example of $this->template->set('load',' '); usage */

$news = new PagedResultSets("SELECT * FROM neko_news ORDER BY id DESC");
$this->template =& new Template($GLOBALS["MooCMS"]["config"]["t_url"].'/show.php');
$this->template->set('load','news');
$this->template->set('news',$news->num_set($GLOBALS["MooCMS"]["config"]["News"]["PerPage"]));
echo $this->template->fetch();
}

}


when I say resembling...I mean the only differences are basically the index of the config array,the sql queries,and which value $this->template->set('load','value'); contains.


class GiantClass
{
var $load;
var $template;
function GiantClass($load = $GLOBALS["config"]["DefaultLoad"])
{
$this->load = $load;
}
function Show()
{
/* db query setup and such*/

$this->template =& new Template($GLOBALS["MooCMS"]["config"]["t_url"].'/show.php');
$this->template->set('load',$this->load);
$this->template->set('news',$news->num_set($GLOBALS["MooCMS"]["config"]["News"]["PerPage"]));
echo $this->template->fetch();

}
}


obviously thats an example used to illustrate what I mean..but you get the idea...basically compact it into one class or such....so what do you all think?multiple classes definately promotes readability...but...I'm the only one who needs to read it ;)..I'm coming from the standpoint that one class may be easier to maintainence...at least one class for the 'common' things...specific things could be in their own class...meh...any thoughts?personal preference I guess. make it one class and if you need add another to continue or to (extend).Originally posted by scoutt
personal preference I guess. make it one class and if you need add another to continue or to (extend).

hmm...so it is indeed perference?theres no real advantage to either except perhaps one class being easier to 'drop' into other scripts?(not an issue here....a cms is a cms..it isn't gonna need to be dropped into anything :D),I think atm since it is a beta designed to let me rapidly add features I need,I may leave it like it is...but once the feature code is somewhat complete...I may change it....
 
Back
Top