07.06.2013 Views

Classi astratte ed interfacce - Dipartimento di Ingegneria Informatica ...

Classi astratte ed interfacce - Dipartimento di Ingegneria Informatica ...

Classi astratte ed interfacce - Dipartimento di Ingegneria Informatica ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010<br />

Interfacce – Implementazione<br />

Una interfaccia definisce una astrazione <strong>di</strong> dato in termini <strong>di</strong><br />

comportamento osservabile, per sua natura però non<br />

implementa nulla.<br />

Qualcuno dovrà prima o poi implementare la astrazione definita<br />

dall’interfaccia. A questo fine, una classe può implementare (una<br />

o più) <strong>interfacce</strong> tramite la keyword implements; in tal caso, la<br />

classe deve implementare tutti i meto<strong>di</strong> richiesti, pena errore <strong>di</strong><br />

compilazione.<br />

Una classe può anche implementare più <strong>interfacce</strong>; deve<br />

comunque fornire implementazione per tutti i meto<strong>di</strong> previsti<br />

se le <strong>interfacce</strong> da implementare prev<strong>ed</strong>ono meto<strong>di</strong> con la stessa<br />

signature, o se la classe implementa un’interfaccia estesa che ha<br />

operato l’overri<strong>di</strong>ng, l’implementazione fornita per tutti quei<br />

meto<strong>di</strong> che hanno (in un modo o in un altro) la stessa signature<br />

è unica; non è detto che essa tuttavia sod<strong>di</strong>sfi tutti i contratti<br />

28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!