Bonjour,

Je me suis décidé à voir à quoi ressemble la programmation objet, et j'aimerais votre avis sur la classe mère et fille ci-dessous. Pour m'exercer, j'ai créé un objet qui n'a sans doute aucune utilité : un formulaire
Celui-ci créé un champ texte et un bouton submit.

Classe mère :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php 
 
class Form
{
    private $nom;
    private $method;
    private $action;
 
    public function __construct($nom, $method, $action)
    {
        $this->nom = $nom;
        $this->method = $method;
        $this->action = $action;
    }
 
    public function NomForm()
    {
        return $this->nom;
    }
 
    public function NomMethod()
    {
        return $this->method;
    }
 
    public function NomAction()
    {
        return $this->action;
    }
}
 
?>
Classe fille :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php 
 
class Formulaire extends Form
{
    public function creationForm()
    {
        if(($this->NomForm()) && ($this->NomMethod()))
        {
            return "<form name='".$this->NomForm()."' id='".$this->NomForm()."' method='".$this->NomMethod()."' action='".$this->NomAction()."' >";
        }
    }
 
    public function input($nom, $value, $taille)
    {
        return $input = "<input type='text' name='$nom' id='$nom' value='$value' size='$taille' />";
    }
 
    public function bouton($type, $nom, $value, $taille)
    {
        return $bouton = "<input type='$type' name='$nom' id='$nom' value='$value' size='$taille' />";
    }
}
 
 
?>
La page de test :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php 
include('FORM.class.php'); // Classe mère
include('Formulaire.FORM.class.php'); // Classe fille
 
$form = new Formulaire("form1", "POST", "$_SERVER[PHP_SELF]", "2");
 
echo $form->creationForm();
echo $form->input("prenom","","15");
echo $valider = $form->bouton("submit", "valider", "Valider", "20");
echo "</form>";
 
if(isset($_POST['valider']))
{
    echo $_POST['prenom'];
}
?>