Design pattern > Créateurs > Factory Method
Ce patron fournit une interface pour créer un objet qui laisse la possibilité aux sous-classes de décider quel type d'objet créer.
Ce patron est utilisé lorsque la classe d'un objet n'est pas connue au moment de la compilation.
Une méthode pour créer un objet factory method est définie dans une classe abstraite, et implémentée dans les différentes sous-classes.
La factory method peut également comporter une implémentation par défaut.
Product (Page)
- defines the interface of objects the factory method creates
ConcreteProduct (SkillsPage, EducationPage, ExperiencePage)
- implements the Product interface
Creator (Document)
- declares the factory method, which returns an object of type Product. Creator may also define a default implementation of the factory method that returns a default ConcreteProduct object.
- may call the factory method to create a Product object.
ConcreteCreator (Report, Resume)
- overrides the factory method to return an instance of a ConcreteProduct.
Resume -------
SkillsPage
EducationPage
ExperiencePage
Report -------
IntroductionPage
ResultsPage
ConclusionPage
SummaryPage
BibliographyPage