<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Constructeur-Programmation-Orientee-Objet | Dr. Goulu</title><link>https://drgoulu.com/tag/constructeur-programmation-orientee-objet/</link><atom:link href="https://drgoulu.com/tag/constructeur-programmation-orientee-objet/index.xml" rel="self" type="application/rss+xml"/><description>Constructeur-Programmation-Orientee-Objet</description><generator>HugoBlox Kit (https://hugoblox.com)</generator><language>fr-FR</language><lastBuildDate>Mon, 06 May 2019 00:00:00 +0000</lastBuildDate><image><url>https://drgoulu.com/media/icon_hu_8d57a97d564ea9bb.png</url><title>Constructeur-Programmation-Orientee-Objet</title><link>https://drgoulu.com/tag/constructeur-programmation-orientee-objet/</link></image><item><title>Pourquoi les objets intégrés mutables ne peuvent-ils pas être transformés en Python ? Quel est l'avantage de cela ?</title><link>https://drgoulu.com/2019/05/06/pourquoi-les-objets-integres-mutables-ne-peuvent-ils-pas-etre-transformes-en-python-quel-est-l-avantage-de-cela/</link><pubDate>Mon, 06 May 2019 00:00:00 +0000</pubDate><guid>https://drgoulu.com/2019/05/06/pourquoi-les-objets-integres-mutables-ne-peuvent-ils-pas-etre-transformes-en-python-quel-est-l-avantage-de-cela/</guid><description>&lt;p&gt;&lt;em&gt;Article initialement publié sur
&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;qu’appelez-vous “transformés” ? Vous voulez dire modifiés comme&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;a=(1,&amp;#39;truc&amp;#39;,true) # tuple
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;a[1]=&amp;#39;machin&amp;#39; # erreur
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;? Alors vous voulez plutôt dire
(immutable en anglais).&lt;/p&gt;
&lt;p&gt;Un objet immutable permet de garantir la cohérence des données qu’il contient en obligeant à les manipuler comme un tout. Ca peut être utile en programmation multi-thread par exemple : chaque thread est sure que l’objet partagé n’est pas en train d’être modifié par une autre thread.&lt;/p&gt;
&lt;p&gt;Un autre avantage est que le hash d’un objet immuable est constant, ce qui permet la recherche très rapide d’un tel objet dans un set ou un dict. C’est pourquoi les clés de dict doivent être de type immuable&lt;/p&gt;</description></item><item><title>Est-il possible de créer des méthodes statiques en Python et de les appeler sans initialiser une classe, comme par exemple : ClassName.StaticMethod ()?</title><link>https://drgoulu.com/2019/05/02/est-il-possible-de-creer-des-methodes-statiques-en-python-et-de-les-appeler-sans-initialiser-une-classe-comme-par-exemple-classname-staticmethod/</link><pubDate>Thu, 02 May 2019 00:00:00 +0000</pubDate><guid>https://drgoulu.com/2019/05/02/est-il-possible-de-creer-des-methodes-statiques-en-python-et-de-les-appeler-sans-initialiser-une-classe-comme-par-exemple-classname-staticmethod/</guid><description>&lt;p&gt;&lt;em&gt;Article initialement publié sur
&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;oui, ça se fait à l’aide du décorateur @staticmethod qui sert exactement à ça:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;class MyClass:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; @staticmethod
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; def staticmethod():
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; return &amp;#39;static method called&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;on peut ensuite appeler soit&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;MyClass().staticmethod(); # crée un objet, puis appelle sa méthode qui est statique
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;soit&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;MyClass.staticmethod(); # appelle directement la méthode statique
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;les décorateurs, c’est absolument génialement fabuleusement puissant et simple&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;</description></item></channel></rss>