lezione 03 - interface
TRANSCRIPT
![Page 1: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/1.jpg)
Ingegneria del Software
![Page 2: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/2.jpg)
Introduzione al pattern…
![Page 3: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/3.jpg)
Ingegneria del Software - A.A. 2003/2004
Problema introduttivo (1/4)
• Durante la progettazione di un software amministrativo, si prevede la presenza di una classe AddressPanel che riesce a visualizzare correttamente gli indirizzi di tutte le classi che contengono un indirizzo.– Clienti– Fornitori– Commercialista– Avvocato– Impiegati– …
Come garantire la coerenza nelle firme dei metodi?Es. String getAddress()
Come garantire la coerenza nelle firme dei metodi?Es. String getAddress()
![Page 4: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/4.jpg)
Ingegneria del Software - A.A. 2003/2004
Problema introduttivo (2/4)
![Page 5: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/5.jpg)
Ingegneria del Software - A.A. 2003/2004
Problema introduttivo (3/4)
AddressIF
ReceivingLocation
![Page 6: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/6.jpg)
Ingegneria del Software - A.A. 2003/2004
Problema introduttivo (4/4)
![Page 7: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/7.jpg)
Presentazione del pattern Interface
![Page 8: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/8.jpg)
Ingegneria del Software - A.A. 2003/2004
Il pattern Interface (1/4)
• Nome Interface [GoF95]
• Synopsis Rende una classe che usa dati e dai servizi offerti da istanze di altre classi indipendente da queste ultime. Ciò è possibile perché la classe in questione accede alle istanze attraverso un interfaccia.
• Context Cfr. esempio introduttivo
• Forces Quando si è costretti a richiedere a una o più classi l’implementazione di uno o più metodi
![Page 9: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/9.jpg)
Ingegneria del Software - A.A. 2003/2004
Il pattern Interface (2/4)
Da Context…
… a Solution
• Solution - Gli “attori” delpattern Interface sono:
– Client
– IndirectionIF
– Service
![Page 10: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/10.jpg)
Ingegneria del Software - A.A. 2003/2004
Il pattern Interface (3/4)
• Consequences
- Permette la separazione tra la definizione dei metodie la loro implementazione
- Può rendere il programma più difficile da capire
![Page 11: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/11.jpg)
Ingegneria del Software - A.A. 2003/2004
Il pattern Interface (4/4)
• Implementation Cfr. esempio introduttivo
• Java API usage Esercizio:Riconoscere il pattern Interface in java.io.FilenameFilter
• Code example Cfr. esempio introduttivo
• Related Patterns Spesso usato insieme al Delegation Pattern
![Page 12: Lezione 03 - Interface](https://reader038.vdocuments.pub/reader038/viewer/2022103117/559729f61a28ab58708b4594/html5/thumbnails/12.jpg)
Ingegneria del Software - A.A. 2003/2004
Domande?