I'm basically creating a display-module for an ad-system I've created.
I'm trying to avoid the following construction, with repeated if-statements.
My gut feeling tells me there's a smarter way to do this, maybe 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') {}
}
}
}
?>