SlideShare uma empresa Scribd logo
1 de 12
Baixar para ler offline
UML + Python




                 Le minimum


                        Python

               UML


                              Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
CLASSE
UML + Python




                                                        Attribut:
                                                        chaque CompteCourant a le sien




                   Opération:
                   chaque CompteCourant sait le faire




                                                         Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
CLASSE
UML + Python




                    class CompteCourant(object):
                        def __init__(self):
                            # A la création, le solde est à zéro
                            self.solde = 0 # Solde en cents!

                        def crediter(self, montant):
                            self.solde += montant

                        def debiter(self, montant):
                            if self.solde < montant:
                                raise OperationRejetee();

                            self.solde -= montant


                                           Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
INTERFACE
UML + Python




                 Tous les Comptes possèdent les 
                       mêmes opérations
                                     Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
INTERFACE
UML + Python



                               Python est dynamique

                 Pas besoin de coder les interfaces

                        class CompteSurLivret(object):
                            def __init__(self, plafond):
                                # ...

                            # ...

                        class CompteCourant(object):
                            def __init__(self):
                                # ...

                            # ...

                                              Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
INTERFACE – option 1
UML + Python


                                  class Compte(object):

                Créer un stub         def crediter(self, montant):
                                          pass

               pour l'interface       def debiter(self, montant):
                                          pass


                                  class CompteSurLivret(Compte):
                                      def __init__(self, plafond):
                                          # ...


                 Faire hériter        # ...


                  les classes     class CompteCourant(Compte):
                                      def __init__(self):
                                          # ...

                                      # ...

                                              Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
INTERFACE – option 2
UML + Python


                                 class Compte(object):

                Variante avec        def crediter(self, montant):
                                         raise NonMisEnOeuvre()

                 exceptions          def debiter(self, montant):
                                         raise NonMisEnOeuvre()


                                 class CompteSurLivret(Compte):
                                     def __init__(self, plafond):
                                         # ...


                Faire hériter        # ...


                 les classes     class CompteCourant(Compte):
                                     def __init__(self):
                                         # ...

                                     # ...

                                             Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
HÉRITAGE
                     Quand la classe de base fait 
UML + Python




                   quelque­chose d'utile, on parle 
                                       d'héritage
                      class Compte(object):
                          def afficheSolde(self):
                              print "%+10.2f" % (self.solde / 100.0)

                          # ...

                      class CompteSurLivret(Compte):
                          # ...


                      if __name__ == '__main__':
                          compte = CompteSurLivret(10000)

                          compte.crediter(10000)
                          compte.afficheSolde()

                                           Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
AGRÉGATION
UML + Python




                     Chaque Client 
                possède un Compte

                class Client(object):
                    def __init__(self, compte):
                        self.compte = compte

                if __name__ == '__main__':
                    # John possède un compte courant
                    john = Client( CompteCourant() )
                    # Paul possède un compte sur livret
                    paul = Client( CompteSurLivret(5000000) )



                                                    Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
AGRÉGATION
UML + Python

                  class Client(object):
                      def __init__(self):
                          self.compte = []

                      def ajouteCompte(self, compte):
                          self.compte.append(compte)

                  if __name__ == '__main__':
                      ringo = Client()
                      ringo.ajouteCompte( CompteCourant() )
                      ringo.ajouteCompte( CompteCourant(5000000) )




                                  Chaque Client 
                                  possède des Comptes

                                              Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
DIAGRAMME
UML + Python



               DE SÉQUENCE

               if __name__ == '__main__':
                   unCompte = CompteCourant()
                   unCompte.crediter(10000)
                   unCompte.afficheSolde()




                                                Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
A VOUS DE JOUER!
UML + Python




                      Q&
                          R

                            Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0

Mais conteúdo relacionado

Mais procurados

Architecture des Systèmes Logiciels
Architecture des Systèmes LogicielsArchitecture des Systèmes Logiciels
Architecture des Systèmes LogicielsGhazouani Mahdi
 
Exercice 1 java Héritage
Exercice 1 java HéritageExercice 1 java Héritage
Exercice 1 java HéritageNadaBenLatifa
 
diagramme de classe
diagramme de classediagramme de classe
diagramme de classeAmir Souissi
 
Base de donnees Avancees et Intro à NoSQL.ppt
Base de donnees Avancees et Intro à  NoSQL.pptBase de donnees Avancees et Intro à  NoSQL.ppt
Base de donnees Avancees et Intro à NoSQL.pptIdriss22
 
Mohamed youssfi support architectures logicielles distribuées basées sue les ...
Mohamed youssfi support architectures logicielles distribuées basées sue les ...Mohamed youssfi support architectures logicielles distribuées basées sue les ...
Mohamed youssfi support architectures logicielles distribuées basées sue les ...ENSET, Université Hassan II Casablanca
 
Fondamentaux java
Fondamentaux javaFondamentaux java
Fondamentaux javaInes Ouaz
 
Cours python avancé
Cours python avancéCours python avancé
Cours python avancépierrepo
 
Android-Tp2: liste et adaptateurs
Android-Tp2: liste et adaptateursAndroid-Tp2: liste et adaptateurs
Android-Tp2: liste et adaptateursLilia Sfaxi
 
eServices-Chp5: Microservices et API Management
eServices-Chp5: Microservices et API ManagementeServices-Chp5: Microservices et API Management
eServices-Chp5: Microservices et API ManagementLilia Sfaxi
 
Chp2 - Vers les Architectures Orientées Services
Chp2 - Vers les Architectures Orientées ServicesChp2 - Vers les Architectures Orientées Services
Chp2 - Vers les Architectures Orientées ServicesLilia Sfaxi
 

Mais procurados (20)

Architecture des Systèmes Logiciels
Architecture des Systèmes LogicielsArchitecture des Systèmes Logiciels
Architecture des Systèmes Logiciels
 
Diagramme d'activité en UML
Diagramme d'activité en UMLDiagramme d'activité en UML
Diagramme d'activité en UML
 
Exercice 1 java Héritage
Exercice 1 java HéritageExercice 1 java Héritage
Exercice 1 java Héritage
 
Cours JavaScript
Cours JavaScriptCours JavaScript
Cours JavaScript
 
diagramme de classe
diagramme de classediagramme de classe
diagramme de classe
 
COURS_PYTHON_22.ppt
COURS_PYTHON_22.pptCOURS_PYTHON_22.ppt
COURS_PYTHON_22.ppt
 
Support de cours technologie et application m.youssfi
Support de cours technologie et application m.youssfiSupport de cours technologie et application m.youssfi
Support de cours technologie et application m.youssfi
 
Sécurité des Applications Web avec Json Web Token (JWT)
Sécurité des Applications Web avec Json Web Token (JWT)Sécurité des Applications Web avec Json Web Token (JWT)
Sécurité des Applications Web avec Json Web Token (JWT)
 
Base de donnees Avancees et Intro à NoSQL.ppt
Base de donnees Avancees et Intro à  NoSQL.pptBase de donnees Avancees et Intro à  NoSQL.ppt
Base de donnees Avancees et Intro à NoSQL.ppt
 
Support JEE Servlet Jsp MVC M.Youssfi
Support JEE Servlet Jsp MVC M.YoussfiSupport JEE Servlet Jsp MVC M.Youssfi
Support JEE Servlet Jsp MVC M.Youssfi
 
Support de cours angular
Support de cours angularSupport de cours angular
Support de cours angular
 
Mohamed youssfi support architectures logicielles distribuées basées sue les ...
Mohamed youssfi support architectures logicielles distribuées basées sue les ...Mohamed youssfi support architectures logicielles distribuées basées sue les ...
Mohamed youssfi support architectures logicielles distribuées basées sue les ...
 
Polymorphisme (cours, résumé)
Polymorphisme (cours, résumé)Polymorphisme (cours, résumé)
Polymorphisme (cours, résumé)
 
Python avancé : Classe et objet
Python avancé : Classe et objetPython avancé : Classe et objet
Python avancé : Classe et objet
 
Support de cours Spring M.youssfi
Support de cours Spring  M.youssfiSupport de cours Spring  M.youssfi
Support de cours Spring M.youssfi
 
Fondamentaux java
Fondamentaux javaFondamentaux java
Fondamentaux java
 
Cours python avancé
Cours python avancéCours python avancé
Cours python avancé
 
Android-Tp2: liste et adaptateurs
Android-Tp2: liste et adaptateursAndroid-Tp2: liste et adaptateurs
Android-Tp2: liste et adaptateurs
 
eServices-Chp5: Microservices et API Management
eServices-Chp5: Microservices et API ManagementeServices-Chp5: Microservices et API Management
eServices-Chp5: Microservices et API Management
 
Chp2 - Vers les Architectures Orientées Services
Chp2 - Vers les Architectures Orientées ServicesChp2 - Vers les Architectures Orientées Services
Chp2 - Vers les Architectures Orientées Services
 

Destaque

All about you knee
All about you kneeAll about you knee
All about you kneeConsultonmic
 
Cypyth formation-programmation-objet-en-langage-python
Cypyth formation-programmation-objet-en-langage-pythonCypyth formation-programmation-objet-en-langage-python
Cypyth formation-programmation-objet-en-langage-pythonCERTyou Formation
 
OpenStack Havana, tour d'horizon
OpenStack Havana, tour d'horizonOpenStack Havana, tour d'horizon
OpenStack Havana, tour d'horizonYannick Foeillet
 
SeSQL : un moteur de recherche en Python et PostgreSQL
SeSQL : un moteur de recherche en Python et PostgreSQLSeSQL : un moteur de recherche en Python et PostgreSQL
SeSQL : un moteur de recherche en Python et PostgreSQLParis, France
 
Les langages de programmation sont trop compliqués
Les langages de programmation sont trop compliquésLes langages de programmation sont trop compliqués
Les langages de programmation sont trop compliquésmercury_wood
 
Base NoSql et Python
Base NoSql et PythonBase NoSql et Python
Base NoSql et Pythonyboussard
 
Modelisation agile 03122011
Modelisation agile  03122011Modelisation agile  03122011
Modelisation agile 03122011agnes_crepet
 
Chp3 - Diagramme de Classes
Chp3 - Diagramme de ClassesChp3 - Diagramme de Classes
Chp3 - Diagramme de ClassesLilia Sfaxi
 
Python et son intégration avec Odoo
Python et son intégration avec OdooPython et son intégration avec Odoo
Python et son intégration avec OdooHassan WAHSISS
 
Vijay Mewada June 11
Vijay Mewada June 11Vijay Mewada June 11
Vijay Mewada June 11vsa177
 
20101109 college univ-leiden_oj
20101109 college univ-leiden_oj20101109 college univ-leiden_oj
20101109 college univ-leiden_ojOlaf Janssen
 
Gripex Kichajacy Portal 2006
Gripex Kichajacy Portal 2006Gripex Kichajacy Portal 2006
Gripex Kichajacy Portal 2006Next
 
Going mobile in accounting education upload
Going mobile in accounting education uploadGoing mobile in accounting education upload
Going mobile in accounting education uploadYaneli Cruz
 

Destaque (20)

All about you knee
All about you kneeAll about you knee
All about you knee
 
Cypyth formation-programmation-objet-en-langage-python
Cypyth formation-programmation-objet-en-langage-pythonCypyth formation-programmation-objet-en-langage-python
Cypyth formation-programmation-objet-en-langage-python
 
OpenStack Havana, tour d'horizon
OpenStack Havana, tour d'horizonOpenStack Havana, tour d'horizon
OpenStack Havana, tour d'horizon
 
La sabiduría
La sabiduríaLa sabiduría
La sabiduría
 
Solucion y Psicologia del Bienestar
Solucion y Psicologia del BienestarSolucion y Psicologia del Bienestar
Solucion y Psicologia del Bienestar
 
Python debugger
Python debuggerPython debugger
Python debugger
 
SeSQL : un moteur de recherche en Python et PostgreSQL
SeSQL : un moteur de recherche en Python et PostgreSQLSeSQL : un moteur de recherche en Python et PostgreSQL
SeSQL : un moteur de recherche en Python et PostgreSQL
 
Les langages de programmation sont trop compliqués
Les langages de programmation sont trop compliquésLes langages de programmation sont trop compliqués
Les langages de programmation sont trop compliqués
 
Base NoSql et Python
Base NoSql et PythonBase NoSql et Python
Base NoSql et Python
 
Modelisation agile 03122011
Modelisation agile  03122011Modelisation agile  03122011
Modelisation agile 03122011
 
Chp3 - Diagramme de Classes
Chp3 - Diagramme de ClassesChp3 - Diagramme de Classes
Chp3 - Diagramme de Classes
 
Python et son intégration avec Odoo
Python et son intégration avec OdooPython et son intégration avec Odoo
Python et son intégration avec Odoo
 
Widgets
WidgetsWidgets
Widgets
 
malik banner
malik bannermalik banner
malik banner
 
Vijay Mewada June 11
Vijay Mewada June 11Vijay Mewada June 11
Vijay Mewada June 11
 
20101109 college univ-leiden_oj
20101109 college univ-leiden_oj20101109 college univ-leiden_oj
20101109 college univ-leiden_oj
 
Gripex Kichajacy Portal 2006
Gripex Kichajacy Portal 2006Gripex Kichajacy Portal 2006
Gripex Kichajacy Portal 2006
 
Facebook2E-mail
Facebook2E-mailFacebook2E-mail
Facebook2E-mail
 
Going mobile in accounting education upload
Going mobile in accounting education uploadGoing mobile in accounting education upload
Going mobile in accounting education upload
 
My Future
My FutureMy Future
My Future
 

Mais de Sylvain Leroux

Mais de Sylvain Leroux (8)

ModèLes DexéCution
ModèLes DexéCutionModèLes DexéCution
ModèLes DexéCution
 
Le Jdk En 5 Minutes
Le Jdk En 5 MinutesLe Jdk En 5 Minutes
Le Jdk En 5 Minutes
 
Java Platform
Java PlatformJava Platform
Java Platform
 
Premier contact avec Subversion
Premier contact avec SubversionPremier contact avec Subversion
Premier contact avec Subversion
 
Notion de fonction en Python
Notion de fonction en PythonNotion de fonction en Python
Notion de fonction en Python
 
Poo
PooPoo
Poo
 
Variables variables
Variables variablesVariables variables
Variables variables
 
Merise vs UML
Merise vs UMLMerise vs UML
Merise vs UML
 

Último

gestion des conflits dans les entreprises
gestion des  conflits dans les entreprisesgestion des  conflits dans les entreprises
gestion des conflits dans les entreprisesMajdaKtiri2
 
Cours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdfCours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdfssuserc72852
 
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...Faga1939
 
Computer Parts in French - Les parties de l'ordinateur.pptx
Computer Parts in French - Les parties de l'ordinateur.pptxComputer Parts in French - Les parties de l'ordinateur.pptx
Computer Parts in French - Les parties de l'ordinateur.pptxRayane619450
 
Apolonia, Apolonia.pptx Film documentaire
Apolonia, Apolonia.pptx         Film documentaireApolonia, Apolonia.pptx         Film documentaire
Apolonia, Apolonia.pptx Film documentaireTxaruka
 
Boléro. pptx Film français réalisé par une femme.
Boléro.  pptx   Film   français   réalisé  par une  femme.Boléro.  pptx   Film   français   réalisé  par une  femme.
Boléro. pptx Film français réalisé par une femme.Txaruka
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...Nguyen Thanh Tu Collection
 
La nouvelle femme . pptx Film français
La   nouvelle   femme  . pptx  Film françaisLa   nouvelle   femme  . pptx  Film français
La nouvelle femme . pptx Film françaisTxaruka
 
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdfCOURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdfabatanebureau
 
Sidonie au Japon . pptx Un film français
Sidonie    au   Japon  .  pptx  Un film françaisSidonie    au   Japon  .  pptx  Un film français
Sidonie au Japon . pptx Un film françaisTxaruka
 
Bolero. pptx . Film de A nnne Fontaine
Bolero. pptx . Film   de  A nnne FontaineBolero. pptx . Film   de  A nnne Fontaine
Bolero. pptx . Film de A nnne FontaineTxaruka
 
Cours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfCours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfachrafbrahimi1
 

Último (13)

gestion des conflits dans les entreprises
gestion des  conflits dans les entreprisesgestion des  conflits dans les entreprises
gestion des conflits dans les entreprises
 
Cours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdfCours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdf
 
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
 
Computer Parts in French - Les parties de l'ordinateur.pptx
Computer Parts in French - Les parties de l'ordinateur.pptxComputer Parts in French - Les parties de l'ordinateur.pptx
Computer Parts in French - Les parties de l'ordinateur.pptx
 
Apolonia, Apolonia.pptx Film documentaire
Apolonia, Apolonia.pptx         Film documentaireApolonia, Apolonia.pptx         Film documentaire
Apolonia, Apolonia.pptx Film documentaire
 
Boléro. pptx Film français réalisé par une femme.
Boléro.  pptx   Film   français   réalisé  par une  femme.Boléro.  pptx   Film   français   réalisé  par une  femme.
Boléro. pptx Film français réalisé par une femme.
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
 
Evaluación Alumnos de Ecole Victor Hugo
Evaluación Alumnos de Ecole  Victor HugoEvaluación Alumnos de Ecole  Victor Hugo
Evaluación Alumnos de Ecole Victor Hugo
 
La nouvelle femme . pptx Film français
La   nouvelle   femme  . pptx  Film françaisLa   nouvelle   femme  . pptx  Film français
La nouvelle femme . pptx Film français
 
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdfCOURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
 
Sidonie au Japon . pptx Un film français
Sidonie    au   Japon  .  pptx  Un film françaisSidonie    au   Japon  .  pptx  Un film français
Sidonie au Japon . pptx Un film français
 
Bolero. pptx . Film de A nnne Fontaine
Bolero. pptx . Film   de  A nnne FontaineBolero. pptx . Film   de  A nnne Fontaine
Bolero. pptx . Film de A nnne Fontaine
 
Cours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfCours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdf
 

UML+Python

  • 1. UML + Python Le minimum Python UML Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 2. CLASSE UML + Python Attribut: chaque CompteCourant a le sien Opération: chaque CompteCourant sait le faire Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 3. CLASSE UML + Python class CompteCourant(object): def __init__(self): # A la création, le solde est à zéro self.solde = 0 # Solde en cents! def crediter(self, montant): self.solde += montant def debiter(self, montant): if self.solde < montant: raise OperationRejetee(); self.solde -= montant Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 4. INTERFACE UML + Python Tous les Comptes possèdent les  mêmes opérations Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 5. INTERFACE UML + Python Python est dynamique Pas besoin de coder les interfaces class CompteSurLivret(object): def __init__(self, plafond): # ... # ... class CompteCourant(object): def __init__(self): # ... # ... Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 6. INTERFACE – option 1 UML + Python class Compte(object): Créer un stub  def crediter(self, montant): pass pour l'interface def debiter(self, montant): pass class CompteSurLivret(Compte): def __init__(self, plafond): # ... Faire hériter # ... les classes class CompteCourant(Compte): def __init__(self): # ... # ... Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 7. INTERFACE – option 2 UML + Python class Compte(object): Variante avec  def crediter(self, montant): raise NonMisEnOeuvre() exceptions def debiter(self, montant): raise NonMisEnOeuvre() class CompteSurLivret(Compte): def __init__(self, plafond): # ... Faire hériter # ... les classes class CompteCourant(Compte): def __init__(self): # ... # ... Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 8. HÉRITAGE Quand la classe de base fait  UML + Python quelque­chose d'utile, on parle  d'héritage class Compte(object): def afficheSolde(self): print "%+10.2f" % (self.solde / 100.0) # ... class CompteSurLivret(Compte): # ... if __name__ == '__main__': compte = CompteSurLivret(10000) compte.crediter(10000) compte.afficheSolde() Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 9. AGRÉGATION UML + Python Chaque Client  possède un Compte class Client(object): def __init__(self, compte): self.compte = compte if __name__ == '__main__': # John possède un compte courant john = Client( CompteCourant() ) # Paul possède un compte sur livret paul = Client( CompteSurLivret(5000000) ) Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 10. AGRÉGATION UML + Python class Client(object): def __init__(self): self.compte = [] def ajouteCompte(self, compte): self.compte.append(compte) if __name__ == '__main__': ringo = Client() ringo.ajouteCompte( CompteCourant() ) ringo.ajouteCompte( CompteCourant(5000000) ) Chaque Client  possède des Comptes Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 11. DIAGRAMME UML + Python DE SÉQUENCE if __name__ == '__main__': unCompte = CompteCourant() unCompte.crediter(10000) unCompte.afficheSolde() Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0
  • 12. A VOUS DE JOUER! UML + Python Q& R Sylvain Leroux – www.chicoree.fr – 2009 – Licence CC-BY3.0