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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Classi</strong> <strong>astratte</strong><br />

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

Un metodo può essere “de facto” astratto se è privo <strong>di</strong> co<strong>di</strong>ce<br />

ma ha le parentesi graffe {}; lavorare pero’ in questo modo<br />

non ha molto senso, perchè si permette l’istanziazione <strong>di</strong> una<br />

classe (sintatticamente NON astratta) che poi ha meto<strong>di</strong><br />

vuoti; sarebbe stato meglio definire la classe o il metodo<br />

esplicitamente come astratti<br />

Una classe astratta può avere dei costruttori (l’errore si<br />

ottiene solo se si tenta <strong>di</strong> istanziarla); lo scopo potrebbe<br />

essere sempre quello: inserire operazioni comuni che<br />

probabilmente saranno sfruttate dalle sottoclassi (i loro<br />

costruttori quin<strong>di</strong> chiameranno super(…))<br />

4

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

Saved successfully!

Ooh no, something went wrong!