Adresse : Yann.Thierry-Mieg@Lip6.fr 1. COO par lʼexemple 100,50 a, 30 120, 200 x r1 = 25 Graphics Dessin translater(dx, dy) dessiner(g) drawline(x,y,h,l) drawellipse fillrect setcolor setbgcolor() * <interface> * Forme virtua void translate (int dx, dy) = 0; virtual void dessiner(graphics &g) = 0; Carre int x,u; int a, void dessiner (Graphics g) void translater (int dx, int dy) Cercle int x,y; int r; dessiner(); translater();
class carre { " int x; " int y; " int a; " " public : " Carre( int x, int y, int a) :x(x),y(y),a(a) " void dessiner(graphic &g){ g.drarect(x,y,a,a);} " void translate (int dx, int dy){x += dx; y += yx;} }; class cercle { " int x; " int y; " int r; " " public : " Carre( int x, int y, int a) :x(x),y(y),r(a) " void dessiner(graphic &g){ g.drawelllipset(x,y,x,y,r);} " void translate (int dx, int dy){x += dx; y += yx;} }; class Dessin { " typedef vector <Forme *> formes_t " typedef formes_t::iterator formes_it; " formes_t formes; " public : " void dessiner (graphics &g){ " " for(formes_it it = formes.begin(); it!= formes.end(); ++it){ (*it)-> dessiner(g);}} " void translate(int dx, int dy){ " for(formes_it it = formes.begin(); it!= formes.end(); ++it){ (*it)-> translate(dx,dy);}} }; Si dessin hérite de form alors class Dessin : public Forme { " typedef vector <Forme *> formes_t " typedef formes_t::iterator formes_it; " formes_t formes; " public : " void dessiner (graphics &g){ " " for(formes_it it = formes.begin(); it!= formes.end(); ++it){ (*it)-> dessiner(g);}} " void translate(int dx, int dy){ " for(formes_it it = formes.begin(); it!= formes.end(); ++it){ (*it)-> translate(dx,dy);}} }; interface -> que des méthodes virtuelles pure graphique
typedef vector <int> tab_t typedef tab_t :: iterator tab_it; tab_t tab; for(tab_it.it = tab.begin(); it!= tab.end(); ++it){cout <<*it;} OU typedef list <int> tab_t typedef tab_t :: iterator tab_it; for(tlist <int>::iteraot it = tab.begin(); it!= tab.end(); ++it){cout <<*it;} Design Pattern Composite Dessin Dessin Dessin Carre Cercle Dessin * Node Composite Leaf
2. Encapsulation, délégation, héritage interface evenements noyaux m1() Dépendance fonctionelle // opération dans leur signature vs structurelle //attributs structures de données délégation A délègue le traitement m sur B return leb->m1(); A m1(); leb B m1();
3. Design Patterns «Design Patterns, elements of reusable software...» Gauna, Johnson, Vkissides,... 95 y.mieg.free.fr/uml/gof.zip maintenabilité, évolutivité, flexibilité, encapsulation Créationnels Factory / AbstractFactory Singleton Structurels Façade Composite Proxy Decorator Comportemantaux Observes Iterator Factory c client Forme dépendances Carre Cercle Rectangle FormeFactory static Forme * createcarre(x,y,a) static Forme * createcercle(x,y,r) staticforme * createrectangle(x,y,l,h) return new Carre(x,y,a) Rectangle(x,y,a);
Forme xf = new Carre(100,150,30); FormeFactory::createCarre(100,150,30); Composite e = True ^(False v - True) ^ True v not False True ExprBool bool eval() = 0; Or And True False Not eval(); eval() eval() ; bool eval() eval() return l -> eval() r->eval() return l -> eval() && r->eval() return op -> eval()
4. y.mieg.free.fr/efrei-dp/ Produit Qte int qte getprix getref getdesc 1 * < interface > Produit string getref() string getdesc() double getprix() Produit Compose ref desc Produit Simple ref desc prix Somme prix des composants
Produit *jante = new PS(«J01», «jante», 12); Produit *rayon = new PS(3ROI», «rayon», 0.2); ProduitCompose *roue = new PC(«RR12», «roue»); roue-> addcomposant(jante,1) roue->addcomposant(rayon,30); cout<<roue->getprix(); void addcomposant(produit *p, int Qte) { if(qte == 1) Composant.push_back(p) else Composant.pushback(new PQ(p,qte)); } 5. La façade interface Encapuslation c1 c2 c3 classe classe classe classe
classe classe classe classe Facade c1 c2 c3
6. Proxy Virtual Proxy Client * Image getdim() render() Image JPG ImageJPG(path) concret getdim() render() ImageProxy string path dimension setdim() render() return dimension if(concret == NULL) concret = new ImgJPG(path) return concret->render; Proxy Sécurité client Connection if(ip appartient blacklist) râle râle socket --> connect (ip) Coonect(IP) Send(msg) Socket 1 Socket Filtre blacklist Connect() Send(msg) concret -> send(msg)
Proxy réseau client Objet m1(); Objet implemante Proxy m1(); m1(); Inet
7. Decorateur client Component draw() getdim() 1 Panel 3D Border ScrollPane getdim(); draw(); getdim(); return pane->getdim() + (5,5) Forme dessiner(g) 1 Dessin FormeColore color dessin(g)
8. Iterator *it begin()" " " " " it" " " " " " end() collection begin():iterator end():iterator iterator operator++ operator * operator == list, dequeue, set, hash-set ou for(vector<int>::iterator it = tab.begin(); it!= tab.end(); ++it) cout<<*it;
9. Observer 10.