Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Exemple d’héritage en PHP


{filelink=14115}

<?php
     class Formes
     {
          var $x;
          var $y;

          function Formes($x, $y)  {
               $this->deplacer_vers($x, $y);
            }
          function get_x()  {
               return $this->x;
          }
          function get_y()  {
               return $this->y;
          }
          function modifierPosition_x($x)  {
               $this->x = $x;
          }
          function modifierPosition_y($y)  {
               $this->y = $y;
          }
          function deplacer_vers($x, $y)  {
               $this->x = $x;
               $this->y = $y;
          }
          function afficher_Position()  {
               print("Shape is currently at " . $this->get_x() . ":" .
                                                $this->get_y() . "<br />");
          }
          function dessiner()
          {}
     }
     class Rectangle extends Formes
     {
          function Rectangle($x, $y)  {
               parent::Formes($x, $y);
          }
          function dessiner()
          {
               print("Rectangle dessiné à la position " . $this->x . ":" .
                                               $this->y . "<br />");
          }
          function afficher_Position()
          {
               print("La position actuelle du rectangle: " . $this->get_x() . ":" .
                                                 $this->get_y() . "<br />");
          }
     }
     $rect1 = new Rectangle(100, 100);
     $rect1->dessiner();
     $rect1->afficher_Position();
?>

No comments yet.

Leave a Comment