 |
| php draft |
Encore pour PHP, Dans l' exemple ci-dessous est définie dans différents langages une classe
Point avec deux attributs
x et
y. Cette classe contient un constructeur, deux méthodes retournant la valeur des attributs (
getX() et
getY()), une méthode déterminant si le point représente l'origine (
isOrigin()) et une méthode effectuant une translation.
class Point {
private $x;
private $y;
public function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
public function getX() { return $this->x; }
public function getY() { return $this->y; }
public function isOrigin() { return ($this->x == 0) && (
$this->y == 0); }
public function translate
($point) {
return new Point(
$this->x +
$point->x, $this->y +
$point->y);
}
}
by taatjene
Comments