15.06.2013 Views

Dispensa in PDF - Dipartimento di Scienze Ambientali, Informatica e ...

Dispensa in PDF - Dipartimento di Scienze Ambientali, Informatica e ...

Dispensa in PDF - Dipartimento di Scienze Ambientali, Informatica e ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

• Interfacce <strong>di</strong>rette: fanno parte <strong>in</strong>tegrante dell’<strong>in</strong>volucro <strong>di</strong> un<br />

componente. Per esempio una libreria C.<br />

Carnielli Efrem: Programmazione a componenti<br />

Def<strong>in</strong>izione ed uso <strong>di</strong> classi, oggetti ed <strong>in</strong>terfacce<br />

• Interfacce <strong>in</strong><strong>di</strong>rette: ottenute dall’<strong>in</strong>sieme delle <strong>in</strong>terfacce degli oggetti<br />

che compongono un componente a run-time.<br />

Un <strong>in</strong>terfaccia può essere rappresentata <strong>in</strong> entrambe le maniere, tramite il<br />

rettangolo contenente la I oppure tramite il secondo simbolo usato.<br />

La <strong>di</strong>fferenza tra le due tipologie <strong>di</strong> <strong>in</strong>terfaccia sta nel chi fornisce il servizio.<br />

I<br />

Interfaccia <strong>di</strong>retta<br />

Figura 7.9. Interfacce <strong>di</strong>rette e <strong>in</strong><strong>di</strong>rette<br />

obj<br />

obj<br />

obj<br />

Interfaccia <strong>in</strong><strong>di</strong>retta<br />

Un esempio può essere quello dell’<strong>in</strong>terfaccia del correttore grammaticale <strong>di</strong> Word.<br />

Il correttore grammaticale è un componente e l’<strong>in</strong>terfaccia è formata dall’<strong>in</strong>sieme<br />

delle <strong>in</strong>terfacce dei servizi che lo compongono (qu<strong>in</strong><strong>di</strong> è un’<strong>in</strong>terfaccia <strong>in</strong><strong>di</strong>retta).<br />

Non si è a conoscenza <strong>di</strong> come il correttore grammaticale sia stato implementato,<br />

ma si ha la cognizione che deve corrispondere all’<strong>in</strong>terfaccia. In questo modo è<br />

possibile realizzare più implementazioni del correttore, per esempio per ogni<br />

l<strong>in</strong>gua, rispettando le specifiche dell’<strong>in</strong>terfaccia.<br />

Le <strong>in</strong>terfacce sono strettamente legate al concetto <strong>di</strong> contratto.<br />

Tramite un contratto si stabiliscono una sorta <strong>di</strong> “regole” tra client e server: si<br />

stabilisce il modo con il quale il client deve chiedere al server i servizi e come il<br />

server deve fornire i servizi al client. Non esiste la possibilità per analizzare se un<br />

dato componente rispetta il contratto <strong>in</strong> un modo automatico tramite software. Si<br />

può def<strong>in</strong>ire, come contratto, solo l’<strong>in</strong>terfaccia vista come <strong>in</strong>sieme <strong>di</strong> operazioni<br />

tramite le signature, <strong>di</strong> cui abbiamo parlato.<br />

171

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

Saved successfully!

Ooh no, something went wrong!