0% ont trouvé ce document utile (0 vote)
209 vues

Mapping Uml Java FR

Transféré par

Chinh Rox
Copyright
© Attribution Non-Commercial (BY-NC)
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
209 vues

Mapping Uml Java FR

Transféré par

Chinh Rox
Copyright
© Attribution Non-Commercial (BY-NC)
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
Vous êtes sur la page 1/ 24

Analyse et conception

Cours de 1e année ingénieur

[email protected]
http://www.fromeo.fr
Mapping UML - JAVA
Plan
• Introduction
– Mapping UML-Java
– Génération de code vs. reverse engineering (outils)
• UML et Java : concepts OO
– Classe, classe abstraite, interface, héritage, …
• Attributs et getter&setter
– Mapping UML-Java : pas forcément uniforme dans les 2 sens
– Setter -> Contraintes OCL
• Associations
– Pas de concept d’association en Java
– 1-1 ; 1-* ; qualifier ; classe d’association
• Composition et agrégation
• Diagramme de séquences
• Machine à états

[email protected] 3
Introduction
• Mapping UML – Java
– à la main (1e année) : passage de la conception à l’implémentation
– utilisation d’outils (2e année MDA/IDM)

UML Rétro-ingénierie UML

Test Implémentation Génération


de code

Java Java

• Génération de code
– Plusieurs choix de mapping possibles (plusieurs interprétations)
• Rétro-ingénierie
– Le modèle retrouvé peut ne pas être identique au modèle de départ
[email protected] 4
UML et Java
• UML = conception orientée objet
• Java = programmation orientée objet
• UML n’est pas lié à un langage de
programmation en particulier et n’impose même
pas d’utiliser un langage orienté objet
• Parce qu’ils sont orientés objets, UML et Java
ont des concepts en commun qui facilitent le
mapping
– Classe, classe abstraite, interface, héritage, …
• Mais tous les concepts d’UML ne se retrouve
pas forcément dans Java

[email protected] 5
UML et Java (classes)
public class A {
A

AbstractA
public abstract class AbstractA {

A
public class B extends A {

}
B

[email protected] 6
UML et Java (interfaces)
<<interface>> public interface IA {
IA

<<interface>>
IA A

IA
ou

A public class A implements IA {

}
<<interface>>
IA

public interface IB extends IA {

}
<<interface>>
IB

[email protected] 7
Attributs et getter&setter
Person public class Person {
+firstname
public String firstname;
+lastname public String lastname;
+age
public int age;
}

public class Person {


private String firstname;
private String lastname;
Person private int age;
-firstname
-lastname
-age
public String getFirstname() {
+getFirstname()
return this.firstname;
+setFirstname() }
+getLastname()
+setLastname() public void setFirstname(String firstname) {
+getAge() this.firstname = firstname;
+setAge()
}
// ...
} [email protected] 8
Attributs et getter&setter et OCL
Person
public class Person {
+firstname
+lastname private String firstname;
+age private String lastname;
private int age;

public int getAge() {


return this.age;
}
public void setAge(int age) {
{ if(age >= 0) {
context Person this.age = age;
inv: age >= 0 } else {
} throw new InvalidAgeException();
}
}
// ...
}
[email protected] 9
Association
• Le concept d’association d’UML n’existe
pas en Java
A B

public class A association B { //???

[email protected] 10
UML sans association
• Un modèle UML utilisant des associations
peut se traduire en un modèle sans association
• Le mapping vers Java peut alors s’effectuer

A B
public class A {
1
private B b;
}

public class B {

A B }
-b: B

[email protected] 11
Association avec rôle
• Même convention qu’en OCL,
– quand il n’y a pas de rôle : nom de la classe
avec première lettre en minuscule
– quand il y a un rôle : nom du rôle
A +role B
public class A {
1 private B role;
}

public class B {

A B }
-role: B

[email protected] 12
Associations et cardinalités
A B public class A {
1 private B b;
}
OCL self.b : B

A B public class A {
* private Set<B> b;
}
OCL self.b : Set(B)

A B public class A {
* private List<B> b;
{ordered}
}

OCL self.b : OrderedSet(B)

[email protected] 13
Associations [1]
public class A {
private B b;
A B
public A() {
1
b = new B();
}
OCL self.b : B
public B getB() {
return b;
}
}

public class A { public class A {


private B b; private B b;
public A(B b) { public A() {}
this.b = b; public setB(B b) {
} this.b = b;
public B getB() { }
return b; public B getB() {
} return b;
} }
}
[email protected] 14
Associations [*]
public class A {
A B
private Set<B> b;
*

public A() {
b = new HashSet<B>(); OCL self.b : Set(B)
// b = new HashSet<B>();
// b = new CopyOnWriteArraySet<B>();
// b = new … implements Set<>
}

public boolean add(B b) {


return this.b.add(b);
}
public boolean addAll(B... b) {
return this.b.addAll(Arrays.asList(b));
}
public boolean addAll(Collection<B> b) {
return this.b.addAll(b);
}
} [email protected] 15
Associations [*]
public class A {
A B
private Set<B> b;
*

public A(Set<B> b) {
this.b = b; OCL self.b : Set(B)
}

public A(B... b) {
this.b = new HashSet<B>(Arrays.asList(b));
}

[email protected] 16
Associations [*]
public class A {
A B
private Set<B> b;
*

public A() {
b = new HashSet<B>(); OCL self.b : Set(B)
// b = new HashSet<B>();
// b = new CopyOnWriteArraySet<B>();
// b = new … implements Set<>
}

public Set<B> getB() {


return this.b;
}
}
main() {
A a = new A();
a.getB().add(new B());
a.getB().addAll(...);
}
[email protected] 17
Associations [*] {ordered}
public class A {
A B
private List<B> b;
*
{ordered}

public A() {
b = new ArrayList<B>(); OCL self.b : OrderedSet(B)
// b = new LinkedList<B>();
// b = new CopyOnWriteArrayList<B>();
// b = new … implements List<>
}

public List<B> getB() {


return this.b;
}
}
main() {
A a = new A();
a.getB().add(new B());
a.getB().addAll(...);
}
[email protected] 18
Associations qualifiées [0..1]

A B
+id : Type
0..1

public class A {
private Map<K,B> b;
}

K
+key

1
A Tuple

*
+value

1 B

[email protected] 19
Associations qualifiées [*]

A B
+id : Type
*

public class A {
private Map<K,Set<B>> b;
}

K
+key

1
A Tuple

*
+value

* B

[email protected] 20
Association, agrégation,
composition
• ToDo en TD

[email protected] 21
Classes d’association
• ToDo en TD

[email protected] 22
Mapping Sequence Diagram - Java
public class Order {

public void dispatch() {


for(LineItem li : lineItems) {
if(product.value > 10000) {
careful.dispatch();
} else {
regular.dispatch();
}
}
if(needsConfirmation) {
messenger.confirm();
}
}

List<LineItem> lineItems;
Distributor careful;
Distributor regular;
Messenger messenger;
boolean needsConfirmation;
}
[Fowler2003]
[email protected] 23
public class MessageParser {

public boolean put(char c) {

Mapping switch (state) {


case Waiting:
if (c == '<') {
State Machines - Java state = GettingToken;
token = new StringBuffer();
body = new StringBuffer();
}
break;
case GettingToken :
if (c == '>') state = GettingBody;
else token.append(c);
break;
case GettingBody :
if (c == ';') state = Waiting;
else body.append(c);
return true;
}
return false;
}
public StringBuffer getToken() { return token; }
public StringBuffer getBody() { return body; }

private final static int Waiting = 0;


private final static int GettingToken = 1;
private final static int GettingBody = 2;
private int state = Waiting;
[BRJ2005] private StringBuffer token, body;
}
[email protected] 24

Vous aimerez peut-être aussi