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

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

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

Carnielli Efrem: Programmazione a componenti<br />

Pr<strong>in</strong>cipi <strong>di</strong> progettazione<br />

particolare istanza. Ma prima <strong>di</strong> questo ho un code-segment (chiamato spawner o<br />

factory ...) che mi <strong>di</strong>ce come deve essere fatto il record s A*.<br />

Con la prossima figura (3.5) vogliamo dare un'idea generale <strong>di</strong> tutto il<br />

proce<strong>di</strong>mento necessario.<br />

a<br />

b<br />

c<br />

d<br />

A<br />

f() {...}<br />

g() {...}<br />

[ ]<br />

p 2<br />

ret 2<br />

y 3<br />

Caricam ento <strong>di</strong> A<br />

Static<br />

cha<strong>in</strong><strong>in</strong>g,<br />

riferim ento<br />

all’am biente<br />

ritorno<br />

Figura 3.5. Esecuzione <strong>di</strong> una classe<br />

clonatore<br />

d<br />

C REA<br />

a<br />

b<br />

c<br />

A*<br />

d [ ]<br />

f() {...}<br />

g() {...}<br />

CR EA<br />

rif. a d statico<br />

costruttore<br />

costruttore<br />

costruttore<br />

Riem pie i<br />

cam pi<br />

Come <strong>di</strong>cevamo <strong>in</strong> precedenza ho un attributo statico d nella classe A, al<br />

caricamento viene generato un clonatore, che tiene traccia dell'attributo statico per<br />

tutte le istanze <strong>di</strong> A. Il clonatore poi genera un costruttore per ogni istanza della<br />

classe richiesta, e alla chiamata <strong>di</strong> una new() <strong>in</strong>izializza le variabili della classe.<br />

Il clonatore, a questo punto, passa al costruttore l’istanza A* con i relativi campi<br />

56

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

Saved successfully!

Ooh no, something went wrong!