Factory
Problématique
Comment simplifier la construction d’objets complexes?
Solution
function catalogueFactory() { $connexion = databaseConnection() ; $resultat = $connexion->query('SELECT * FROM produits') ; $catalogue = new Catalogue() ; while($enregistrement = $resultat->fetch(PDO::FETCH_ASSOC)) { $catalogue->ajouter( new Produit( $enregistrement['reference'], $enregistrement['libelle'], $enregistrement['categorie'], $enregistrement['prix'], $enregistrement['id_produit'] ) ) ; } return $catalogue ; }
Commentaires récents