18.04.2013 Views

Tehnici de implementare a concurentei în analiza si proiectarea ...

Tehnici de implementare a concurentei în analiza si proiectarea ...

Tehnici de implementare a concurentei în analiza si proiectarea ...

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.

Din diagrama prezentata <strong>în</strong> figura 2.4 <strong>de</strong>ducem ca un obiect al clasei Coada se<br />

poate afla <strong>în</strong>tr-una din urmatoarele stari: Gol, Plin sau Partial. Implementarea clasei<br />

Coada realizata pe baza acestei diagrame <strong>de</strong>fineste aceste trei stari <strong>în</strong> cadrul sectiunii<br />

behavior <strong>si</strong> modifica starea obiectelor folo<strong>si</strong>nd instructiunea become asupra<br />

i<strong>de</strong>ntificatorului starii tinta. Constructorii <strong>si</strong> <strong>de</strong>structorul se con<strong>si</strong><strong>de</strong>ra ca facând parte<br />

din interfata obiectului indiferent <strong>de</strong> stare.<br />

class Coada{<br />

protected:<br />

Element listaElemente[]; //tablou cu elementele cozii<br />

int maxElem; //nr. maxim <strong>de</strong> elemente din coada<br />

int elemIntroduse; //nr. elementelor introduse <strong>în</strong> coada<br />

int elemExtrase; //nr. elementelor extrase din coada<br />

public:<br />

Coada();<br />

~Coada(){ . . . };<br />

void Adauga(Element elem);<br />

Element Extrage();<br />

//<strong>de</strong>finirea starilor clasei<br />

behavior:<br />

Plin = {Extrage};<br />

Gol = {Adauga};<br />

Partial = {Extrage, Adauga};<br />

}<br />

Coada::Coada(){<br />

//pentru <strong>si</strong>mplitate nu am <strong>de</strong>finit constructor explicit<br />

maxElem=100;<br />

listaElemente=new [maxElem] Element;<br />

elemIntroduse=elemExtrase=0;<br />

become Gol;<br />

}<br />

void Coada::Adauga(Element elem){<br />

elemIntroduse++;<br />

listaElemente[elemIntroduse % maxElem - 1]=elem;<br />

if (elemIntroduse - elemExtrase == maxElem)<br />

become Plin;<br />

else<br />

become Partial;<br />

}<br />

Element Coada::Extrage(){<br />

elemExtrase++;<br />

Element elem=listaElemente[elemExtrase % maxElem - 1];<br />

if (elemIntroduse - elemExtrase == 0)<br />

become Gol;<br />

else<br />

become Partial;<br />

return elem;<br />

}<br />

Codul <strong>de</strong> coordonare a interactiunilor concurente este <strong>în</strong>tr-un anumit fel mai<br />

izolat. Totu<strong>si</strong> ramân instructiunile become care sunt executate <strong>în</strong> cadrul codului ce<br />

<strong>de</strong>scrie functionalitatea unei clase. Prin urmare nici <strong>în</strong> acest caz nu sunt respectate<br />

principiile izolarii <strong>si</strong> separarii codului <strong>de</strong> interactiune.<br />

Evi<strong>de</strong>nt mecanismele bazate pe abstractizari <strong>de</strong> comportament respecta<br />

principiul codului <strong>de</strong> interactiune orientat pe apelat. Mai mult, datorita conceptului <strong>de</strong><br />

41

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

Saved successfully!

Ooh no, something went wrong!