[eluser].giorgio[/eluser]
also for me this has been quite a problem... I'd like to write my code as much OOP as possible, for the sake of simplicity at the semantic level. I'd rather iterate through objects of, say, a Topic, than iterate through database results (although in the end the same result could be accomplished). I'm eagerly looking for a pattern to implement such a thing using codeigniter and Models (or don't I understand the model principle?). Especially for inheritence and abstraction Models don't suit my needs...
How could i accomplish something like this?
Code:
abstract class Figure {
protected name;
protected location = array('x' => 2, 'y' => 10);
abstract function get_center();
}
class Circle extends Figure {
private $radius = 4;
public function get_center() {
$x = $this->location['x']+$this->radius;
$y = $this->location['y']+$this->radius;
return array('x' => $x, 'y' => $y);
}
}
class Square extends Figure {
private $width;
private $height;
public function get_center() {
$x = $this->location['x']+($this->width/2);
$y = $this->location['y']+($this->height/2);
return array('x'=>$x, 'y'=>$y);
}
}
$figures = array(
new Circle,
new Square,
new Square,
new Circle
);
foreach($figures as $figure) {
$center = $figure->get_center();
echo 'This '. get_class($figure) .'\'s center is located at: ['.$center['x'].','. $center['y'].']<br />';
}