(25 апр 2014, 09:48) (
0/
0)
[
0]
пример вверху!
(25 апр 2014, 09:42) (
0/
0)
[
0]
PHP:
interface RowStrategy {
public function execute(array $row);
}
abstract class FieldPrinterStrategy implements RowStrategy {
abstract protected function getFieldName();
public function execute(array $row) {
echo $row[$this->getFieldName()];
}
}
class NamePrinterStrategy extends FieldPrinterStrategy {
protected function getFieldName() {
return 'name';
}
}
class TextPrinterStrategy extends FieldPrinterStrategy {
protected function getFieldName() {
return 'text';
}
}
class AdDao {
public function applyStrategy(RowStrategy $strategy) {
foreach ($this->fetchAll() as $row)
$strategy->execute($row);
}
}
$adDao->applyStrategy(new NamePrinterStrategy);
$adDao->applyStrategy(new TextPrinterStrategy);