Bonjour à tous,
Lorsque l'on développe des applications d'une certaine taille, il est indispensable de respecter des règles de nommage. Aussi je me pose la question suivante : Quelles règles de nommage utilisées pour développer en Flex / ActionScript? Et, en particulier :
MXML
QUESTION Quelle valeur donner à l'attribut "id" d'une balise MXML?
Je propose : "Id" + "le type de composant (Box)" + "Un nom qui décrit le fonctionnel".
Exemple :
QUESTION Quel nom donner aux fonctions destinées à gérer les évènements?
Je propose : "identifiant du composant qui envoie l'évènement" + "On" + "évènement".
Exemple :
<mx:Button id="IdButtonConfiguration" click="IdButtonConfigurationOnClick(event)"/>
QUESTION Quel nom donner aux composants MXML (fichiers MXML qui décrivent un composant)?
Je propose : "CP" + "Un nom qui décrit le fonctionnel".
Exemple : "CPConfigurationPanel".
ActionScript
QUESTION Quel nom donner aux attributs privés d'une classe?
Je propose : "__" + "Type de l'attibut" + "Un nom qui décrit le fonctionnel".
Exemple :
private var __LabelErrorMessage:Label;
QUESTION Quel nom donner aux attributs publics d'une classe?
Je propose : "Type de l'attibut" + "Un nom qui décrit le fonctionnel".
Exemple :
public var LabelErrorMessage:Label;
QUESTION Quel nom donner à une classe qui gère l'information associée à un composant MXML?
Je propose : "Le nom du composant MXML" + "Data".
Exemple :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?xml version="1.0" encoding="utf-8"?>
<!-- Fichier src/composants/CPConfigurationPanel.mxml -->
<!-- Fichier CPConfigurationPanel.as sous src/composants/CPConfigurationPanel/CPConfigurationPanelData.as -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
width="400"
height="300"
creationComplete="init()">
<mx:Script>
<![CDATA[
import componants.CPConfigurationPanel.CPConfigurationPanelData;
import mx.controls.Button;
import componants.CPConfigurationPanel;
private var CPConfigurationPanelDataHd:CPConfigurationPanelData;
public function init():void
{
CPConfigurationPanelDataHd = new CPConfigurationPanelData();
}
include "CPConfigurationPanel/EventHandlers.as";
]]>
</mx:Script>
<mx:Button id="IdButtonGo" click="IdButtonGoOnClick(event)"/>
</mx:Canvas> |
Arboressence
QUESTION Où placer les codes ActionsScripts associés à un composant MXML?
Je propose : Sous le sous répertoire "componants/NomDuComposant".
Exemple : Si le composant se nomme "CPConfigurationPanel", alors les fichiers AS associés à ce composant seront placés dans le sous-répertoire : "componants/CPConfigurationPanel"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?xml version="1.0" encoding="utf-8"?>
<!-- Fichier src/composants/CPConfigurationPanel.mxml -->
<!-- Fichier CPConfigurationPanel.as sous src/composants/CPConfigurationPanel/CPConfigurationPanelData.as -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
width="400"
height="300"
creationComplete="init()">
<mx:Script>
<![CDATA[
import componants.CPConfigurationPanel.CPConfigurationPanelData;
import mx.controls.Button;
import componants.CPConfigurationPanel;
private var CPConfigurationPanelDataHd:CPConfigurationPanelData;
public function init():void
{
CPConfigurationPanelDataHd = new CPConfigurationPanelData();
}
include "CPConfigurationPanel/EventHandlers.as";
]]>
</mx:Script>
<mx:Button id="IdButtonGo" click="IdButtonGoOnClick(event)"/>
</mx:Canvas> |
QUESTION Où placer les gestionnaires d'évènements liés à un composant MXML?
Je propose : Dans un fichier "EventHandlers.as".
Exemple :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?xml version="1.0" encoding="utf-8"?>
<!-- Fichier src/composants/CPConfigurationPanel.mxml -->
<!-- Fichier CPConfigurationPanel.as sous src/composants/CPConfigurationPanel.as -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
width="400"
height="300"
creationComplete="init()">
<mx:Script>
<![CDATA[
import componants.CPConfigurationPanel.CPConfigurationPanelData;
import mx.controls.Button;
import componants.CPConfigurationPanel;
private var __CPConfigurationPanelDataHd:CPConfigurationPanelData;
public function init():void
{
__CPConfigurationPanelDataHd = new CPConfigurationPanelData();
}
include "CPConfigurationPanel/EventHandlers.as";
]]>
</mx:Script>
<mx:Button id="IdButtonGo" click="IdButtonGoOnClick(event)"/>
</mx:Canvas> |
1 2 3 4 5 6 7 8 9
| // Fichier src/componants/CPConfigurationPanel/CPConfigurationPanelData.as
package componants.CPConfigurationPanel
{
public class CPConfigurationPanelData
{
public function CPConfigurationPanelData() { /* ... */ }
public function go():void { /* ... */ }
}
} |
1 2 3 4 5 6 7 8
| // ActionScript file
// Fichier src/componants/CPConfigurationPanel/EventHandlers.as
import flash.events.Event;
private function IdButtonGoOnClick(event:Event):void
{
__CPConfigurationPanelDataHd.go();
} |
Quelles conventions utilisez-vous pour structurer votre code?
A+ Denis
Partager