4 Implementation
4 Implementation
Refactoring
Model
transformation
Reverse Another
engineering Program
System Model
(in UML)
Model space Source code space
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Model Transformation
Takes as input a model conforming to a
meta model (for example the MOF
metamodel) and produces as output
another model conforming to the
metamodel
Model transformations are used in MDA
(Model Driven Architecture).
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
Model Transformation Example
Object design model before transformation:
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
Program
(in Java)
Yet Another
System Model
Another
System Model Forward
engineering
Refactoring
Model
transformation
Reverse Another
engineering Program
System Model
(in UML)
Model space Source code space
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
Refactoring : Pull Up Field
public class User {
public class Player { private String email;
private String email; }
//... public class Player extends User {
} //...
public class LeagueOwner {
}
private String eMail;
//... public class LeagueOwner extends User {
} //...
public class Advertiser { }
private String email_address; public class Advertiser extends User {
//... //...
} }.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
Refactoring Example: Pull Up Constructor Body
public class User {
public class User {
public User(String email) {
private String email;
this.email = email;
}
}
}
public class Player extends User { public class Player extends User {
public Player(String email) { public Player(String email) {
super(email);
this.email = email; }
} }
}
public class LeagueOwner extends User{ public class LeagueOwner extends User {
public LeagueOwner(String email) {
public LeagueOwner(String email) {
super(email);
this.email = email;
} }
}
}
public class Advertiser extends User{ public class Advertiser extends User {
public Advertiser(String email) { public Advertiser(String email) {
this.email = email; super(email);
}
} }.
}
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
Program
4 Different Types of Transformations (in Java)
Yet Another
System Model
Another
System Model Forward
engineering
Refactoring
Model
transformation
Reverse Another
engineering Program
System Model
(in UML)
Model space Source code space
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
Forward Engineering Example
Object design model before transformation:
User LeagueOwner
-email:String -maxNumLeagues:int
+getEmail():String +getMaxNumLeagues():int
+setEmail(e:String) +setMaxNumLeagues(n:int)
+notify(msg:String)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
Collapsing Objects
Object design model before transformation:
Person SocialSecurity
number:String
Person
SSN:String
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
Examples of Model Transformations
and Forward Engineering
Model Transformations
◦ Goal: Optimizing the object design model
Collapsing objects
Delaying expensive computations
Forward Engineering
◦ Goal: Implementing the object design model in a
programming language
◦ Mapping inheritance
◦ Mapping associations
◦ Mapping contracts to exceptions
◦ Mapping object models to tables
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
Examples of Model Transformations
and Forward Engineering
Model Transformations
◦ Goal: Optimizing the object design model
Collapsing objects
Delaying expensive computations
Forward Engineering
◦ Goal: Implementing the object design model in a
programming language
Mapping inheritance
◦ Mapping associations
◦ Mapping contracts to exceptions
◦ Mapping object models to tables
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
Mapping Associations
1. Unidirectional one-to-one association
2. Bidirectional one-to-one association
3. Bidirectional one-to-many association
4. Bidirectional many-to-many association
5. Bidirectional qualified association.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
Unidirectional one-to-one association
Object design model before transformation:
1 1
Advertiser Account
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
Bidirectional one-to-one association
Object design model before transformation:
Advertiser 1 1 Account
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
Bidirectional many-to-many
association
Object design model before transformation
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23