$object_cin = new CIO( );
$object_cin->invoke( $_POST[ 'model' ] );
class CIO
{
private function invoke( $model )
{
switch( $model )
{
case 'user_try':
$model = new MUserTry();
$this->send( $model->invoke( 1 ) );
break;
case 'user_new':
$model = new MUserNew( new IUniversals() , new IText(), new IMessage() );
$this->send( $model->invoke() );
break;
case 'user_exist':
$model = new MUserExist( new IUniversals() , new IText(), new IMessage() );
$this->send( $model->invoke() );
break;
case 'tweet':
$model = new MTweet( new IUniversals() , new IText(), new IMessage() );
$this->send( $model->invoke() );
break;
default:
echo "Incorrect Ajax Type provided";
}
}
private function send( $string )
{
echo "|P|" . $string;
}
}
$object_cin = new CIO( ); $object_cin->invoke( $_POST[ ‘model’ ] ); class CIO { private
Share
Of course it will grow, and become impossible to maintain.
First of all, what is with the generic
Controlclass? A website is supposed to have multiple controllers (I am assuming that it is somehow related to MVC, because that’s where the term “controller” comes from), usually 1 controller per one “page” (granularity may change, depending on architectural pattern).Next problem is the big
switchstatement. Each of thecase‘s there should be a separate method in a controller. You end up repeating parts of code, just because of the design mistake.