Basically, I create a display module for the created advertising system.
I am trying to avoid the following construct with repeating if statements.
The gut feeling tells me a smarter way to do this, perhaps with polymorphism?
<?php class Ad { public $adState = 'active'; } class AdWriter { public function displayAd(Ad $ad, $viewmode = 'visitor') { if ($viewmode =='visitor') { if ($adState == 'active') {} else if ($adState == 'paused') {} else if ($adState == 'inactive') {} } else if ($viewmode = 'owner') { if ($adState == 'active') {} else if ($adState == 'paused') {} else if ($adState == 'inactive') {} } else if ($viewmode == 'administrator') { if ($adState == 'active') {} else if ($adState == 'paused') {} else if ($adState == 'inactive') {} } } } ?>
Poyan
source share