SlideShare une entreprise Scribd logo
Design Pattern - Factory Pattern
Avec Spring Boot
par James Kokou GAGLO
Objectif
L'objectif avec ce "Design Pattern" est de concevoir une classe qui va instancier
différents types d'objets suivant un paramètre fourni.
Diagramme
Source : https://www.tutorialspoint.com/design_pattern/factory_pattern.htm
Interface et classes
Interface et classes
Interface et classes
● Création de l’interface Shape contenant la méthode draw()
retournant un String
● Création des implémentations de Shape (Circle,
Triangle,Rectangle)
● Création de l’interface ShapeFactory qui contient une
méthode getShape permettant de spécifier l’implémentation
de Shape à renvoyer.
Beans de configuration
Beans de configuration
● Création de bean Spring Boot pour chaque implémentation de Shape. Les
noms des beans permettront au ShapeFactory de renvoyer la bonne instance
de Shape.
● La classe ServiceLocatorFactoryBean permet d’enregistrer notre factory
ShapeFactory afin que Spring Boot puisse trouver les bonnes instances
lorsque la méthode getShape(String shapeType) du ShapeFactory est
appelée en passant le type de Shape.
La classe ShapeService
Démo
Démo
Code source
https://github.com/freemanpolys/spring-boot-labs
Documentation
● https://www.tutorialspoint.com/design_pattern/factory_pattern.htm
● http://docs.spring.io/spring-framework/docs/current/javadoc-api/o
rg/springframework/beans/factory/config/ServiceLocatorFactoryBe
an.html
● http://docs.spring.io/spring-framework/docs/current/javadoc-api/o
rg/springframework/beans/factory/BeanFactory.html
● https://www.tutorialspoint.com/spring/spring_bean_definition.htm

Contenu connexe

PDF
Contributions aux environnements de développement de services de télécoms da...
PDF
Mise en place d’une plateforme de formation IMS
PDF
Guia de laboratorio001_fisica[1]
PPTX
La seguridad de la nube geysi miranda
PPTX
Micosis oportunistas
PPT
Proverbs 6:1-5 Nor Lender Be
PDF
PPT
AmpleHarvest.org - Initial Concept
Contributions aux environnements de développement de services de télécoms da...
Mise en place d’une plateforme de formation IMS
Guia de laboratorio001_fisica[1]
La seguridad de la nube geysi miranda
Micosis oportunistas
Proverbs 6:1-5 Nor Lender Be
AmpleHarvest.org - Initial Concept

Plus de Kokou Gaglo (9)

PDF
Prise en main de Jhipster
PDF
IP Multimedia Subsystem : Démarrer avec Mobicents JainSLEE (Partie 1)
PDF
Mybatis : Spring Data à la rescousse
PDF
Spring Batch
PDF
Intégration continue et déploiement continue avec Jenkins
PDF
Java - Lombok
PDF
MyBatis, une alternative à JPA.
PDF
Serveur http
PDF
Programmation evénementielle
Prise en main de Jhipster
IP Multimedia Subsystem : Démarrer avec Mobicents JainSLEE (Partie 1)
Mybatis : Spring Data à la rescousse
Spring Batch
Intégration continue et déploiement continue avec Jenkins
Java - Lombok
MyBatis, une alternative à JPA.
Serveur http
Programmation evénementielle
Publicité

Design pattern