I have a Display
object that handles HTML output of the script. It has a mode
property, which defines many aspects of how the output is generated. There are several modes, and I will probably add more later. Each mode implies it's own parameters. For example, an author
mode would imply an authorID
. A search
mode would imply a Search
object as a parameter, which would contain query information. A comment
mode would imply a postID
and commentID
parameters.
So, a mode
has a name
and some number of parameters
, depending on the name
.
I decided to create a Display_Mode
object, which has two properties: name
and parameters
. But how do I assign parameters
to names
? So that if I have a comment
mode, it would neccessarily mean that there are postID
and commentID
parameters?
My current solution is this:
class display_mode{
public $name;
public $params;
public function __construct($name)
{
$this->name = $name;
switch ($this->name){
case 'comment':
$this->params = array('postID', `commentID`);
break;
case 'author':
$this->params = array('authorID');
}
//etc..
}
}
This seems a bit messy. Is there a better way?
UPD: given answers led me to ask another question, concerning the whole design, which also provides context for this one.