Download - Design Pattern 4. Factory Pattern
Transcript
- 1.
- Factory Pattern
- Francesco Ierna
2.
- Factory Pattern
- Problem:
- If with many different type of return
3. If we want to add contrete classes we must re-open the code -> not closed for modification Solution:
- Identify the aspects that vary
4. Encaps object creation(Factory) 5.
- FactoryPattern
6.
- FactoryPattern
7.
- Factory Pattern Defined
8.
- Code Factory Method
- Il metodocreatePizza il factory methodinvoca un metodo nella stessa classe che in base alla tipologia di oggetti invoca quello nelle sottoclassi
9. Ex:PizzaStore p = new NewYorkStore(); 10. p.createPizza(jjjj); 11.
- Code Factory
12.
- Code Pizza
- Classe usata per creare l'oggetto con tutti i metodi usati per la creazione della pizza
13.
- Code Pizza Client