schema beans. langage temperature schema temperature publié par...
TRANSCRIPT
![Page 1: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/1.jpg)
Schema Beans
![Page 2: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/2.jpg)
Langage temperature
![Page 3: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/3.jpg)
Schema temperature
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace=”temperature" xmlns="temperature" elementFormDefault="qualified">
<xsd:element name="temperature" type="Temperature"/>
<xsd:complexType name="Temperature"> <xsd:sequence> <xsd:element name="min" type="xsd:int"/> <xsd:element name="max" type="xsd:int"/> </xsd:sequence> </xsd:complexType>
</xsd:schema>
![Page 4: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/4.jpg)
Document instance XML
<temperature xmlns='temperature' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='temperature temperature.xsd'>
<min>3</min><max>12</max>
</temperature>
![Page 5: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/5.jpg)
•Une classe, tout comme un schéma est un modèle
•A partir d’une classe, on peut créer des objets instance, tout comme à partir d’un schéma on peut créer des documents instance
Classes
![Page 6: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/6.jpg)
Structure d’une classe
ChampsConstructeurMéthodes Une classe Temperature doit se trouver
dans un fichier de nom Temperature.java
![Page 7: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/7.jpg)
Classes
Champs
Méthodes
Le constructeur est une méthode servant à créer des objets à partir du modèle. Le nom du constructeur est celui de la classe
new
![Page 8: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/8.jpg)
Objets
•Conformes au modèle décrit dans la classe
•Offrent les méthodes décrites dans la classe
•Ont les champs décrits dans la classe
![Page 9: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/9.jpg)
Programme Java
JVM
Main new
Démarrage du programme par “java Main”. Java désigne la machine virtuelle
![Page 10: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/10.jpg)
•Nous allons voir 3 formes de classes équivalentes au schéma temperature
•Champs public avec accés direct
•Champs privés avec accés par méthodes get/set:
•Méthodes déclarées localement
•Méthodes publiées dans une interface
Classes Java
![Page 11: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/11.jpg)
Champs public avec accés direct
![Page 12: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/12.jpg)
Classe Temperature
public class Temperature {//champs public int min; public int max;//constructeur public Temperature { }}
Champs public: accés direct aux valeurs
![Page 13: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/13.jpg)
Utilisationpublic class Main {
public Main() { }
public static void main(String args[]) { Temperature t = new Temperature(); t.min = 6 ; t.max = 22 ; double m = (t.min + t.max)/2.0; }
}
accés direct aux valeurs
utilisation du constructeur
![Page 14: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/14.jpg)
Champs privés avec accés par méthodes get/set
méthodes déclarées localement
![Page 15: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/15.jpg)
get/set
| get sert à retirer une copie de la valeur| set sert à déposer une valeur
(effacement de l’ancienne)
get/set sont des méthodes permettant l’accés aux champs losrque ceux-ci ne sont pas public
![Page 16: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/16.jpg)
Bean Temperaturepublic class Temperature {//champs private int min; private int max;//constructeur public Temperature { }//methodes d’acces public int getMin() { return min; } public int getMax() { return max; }//methodes de mutation public void setMin(int m) {min=m;} public void setMax(int m) {max=m;}}
Une bean est une classe qui a des méthodes set/get d’accés aux champs
![Page 17: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/17.jpg)
Utilisationpublic class Main {
public Main() { }
public static void main(String args[]) { Temperature t = new Temperature(); t.setMin(6) ; t.setMax(22) ; double m = (t.getMin() + t.getMax())/2.0; }
}
![Page 18: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/18.jpg)
Champs privés avec accés par méthodes get/set méthodes publiées
dans une interface
![Page 19: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/19.jpg)
Interfaces| Une interface est un contrat | Une interface est un engagement
de fournir les méthodes dont la liste se trouve dans le contrat
![Page 20: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/20.jpg)
Interface Temperature
public interface Temperature {
//methodes d’acces public int getMin(); public int getMax();
//methodes de mutation public void setMin(int m); public void setMax(int m);
}
Les interfaces sont des contrats entre un producteur de classes et un utilisateur de classes
![Page 21: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/21.jpg)
Bean TemperatureImpl
public class TemperatureImpl implements Temperature { private int min; private int max; public TemperatureImpl() { }
//méthodes d’accés public int getMin() { return min; } public int getMax() { return max; }
//méthodes de mutation public void setMin(int m) { min = m; } public void setMax(int m) { max = m; } }
Con
tra
tre
mp
li
![Page 22: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/22.jpg)
Utilisationpublic class Main {
public Main() { }
public static void main(String args[]) { Temperature t = new TemperatureImpl(); t.setMin(6) ; t.setMax(22) ; double m = (t.getMin() + t.getMax())/2.0; } }
Seule modification
![Page 23: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/23.jpg)
Interfaces
•Evolution dans le temps
•Changement de l’implementation sans remise en cause du code client
•Masquage d’une implémentation
•Modularité
•une classe peut implémenter plusieurs interfaces
![Page 24: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/24.jpg)
Beans & UML
![Page 25: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/25.jpg)
Beans: get/set
•Les beans sont des classes Java particulières
•Containeurs de données
•Accés aux données par des méthodes de nom getNomDeLaDonnée
•Modification des valeurs par des méthodes de nom setNomDeLaDonnée
![Page 26: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/26.jpg)
Représentation UML
- pour private
+ pour public
Cas d’une “bean” sans interface
![Page 27: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/27.jpg)
Représentation UML
- pour private
+ pour public
Cas d’une “bean” avec interface
![Page 28: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/28.jpg)
Equivalence Types simples
xsd:string java.lang.Stringxsd:integer java.math.BigIntegerxsd:int intxsd.long longxsd:short shortxsd:decimal java.math.BigDecimalxsd:float floatxsd:double doublexsd:boolean booleanxsd:byte bytexsd:QName javax.xml.namespace.QNamexsd:dateTime java.util.Calendarxsd:base64Binary byte[]xsd:hexBinary byte[]xsd:unsignedIn longxsd:unsignedShort intxsd:unsignedByte shortxsd:time java.util.Datexsd:date java.util.Datexsd:anySimpleType java.lang.String
Des types simples xsd deviennent des types complexes Java
Le nom d’un type complex Java (classe)
commence toujours par une majuscule
![Page 29: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/29.jpg)
Documents & Objets
new
documents Objets
![Page 30: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/30.jpg)
Document instance XML
<temperature xmlns='temperature' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='temperature temperature.xsd'>
<min>3</min><max>12</max>
</temperature>
![Page 31: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/31.jpg)
•Création directe par new
•Création indirecte par une fabrique d’objets
Création d’un objet
![Page 32: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/32.jpg)
Création directepublic class Main {
public Main() { }
public static void main(String args[]) { Temperature t = new Temperature(); t.min = 6 ; t.max = 22 ; double m = (t.min + t.max)/2.0; }
}
![Page 33: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/33.jpg)
Pattern ObjectFactory
•public class Main {• public static void main(String[] args) {
• Temperature t = ObjectFactory.createTemperature();
• t.setMin(3) ;• t.setMax(34) ;
• }•}// end class
![Page 34: Schema Beans. Langage temperature Schema temperature Publié par Lance Fontaine, Modifié il y a 8 ans](https://reader035.vdocuments.pub/reader035/viewer/2022062318/551d9dc8497959293b8e35fb/html5/thumbnails/34.jpg)
Programme Java
JVM
Main
ObjectFactory
new
new
Démarrage du programme par “java Main”. Java désigne la machine virtuelle
Temperature