Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Lecture #12
Software Engineering and Project Management
Instructed by Steven Choy on Jan 22, 2007
* Deployment
Overview
Source: ObjectOriented Software Engineering by Bruegge and Dutoit
3
Mapping Concepts
Forward engineering Refactoring Model transformation Reverse engineering Model space Source code space
Model Transformation
Object design model before transformation
LeagueOwner +email:Address Advertiser +email:Address Player +email:Address
Refactoring
Operate on source code, ie. Improving a single aspect of the system without changing its functionality
public class User { private String email; } public class Player extends User { //... } public class LeagueOwner extends User { //... } public class Advertiser extends User { //... }
public class Player { private String email; //... } public class LeagueOwner { private String eMail; //... } public class Advertiser { private String email_address; //... }
5
+email:Address
LeagueOwner
Advertiser
Player
Forward Engineering
Object design model before transformation
User +email:String +notify(msg:String) LeagueOwner +maxNumLeagues:int
Produce a code template that corresponds to an object model.
public class LeagueOwner extends User { private int maxNumLeagues; public int getMaxNumLeagues() { return maxNumLeagues; } public void setMaxNumLeagues (int value) { maxNumLeagues = value; } /* Other methods omitted */ }
Reverse Engineering
Applied to a set of source code elements and results in a set of model elements Recreate the model for an existing system
private Account account; public Student() { account = new Account(); } public Account getAccount() { return account; } }
9 10
One-to-Many Association
public class Student { private Account account; public Student() { account = new Account(this); } public Account getAccount() { return account; } }
public class Account { private Student owner; public Account(Student student) { owner = student; } public Student getOwner() { return student; } }
11
public class Student { private Set accounts; public Student() { accounts = new HashSet(); } public void addAccount(Account account) { accounts.add(account); } public Account removeAccount(Account account) { accounts.remove(account); } }
12
Many-to-Many Association
Qualified Associations
public class Student { private List courses; public Student() { courses = new ArrayList(); } public void addCourse(Course course) { if (!courses.contains(course)) { courses.add(course); course.addStudent(this); } } }
public class Course { private List students; public Course() { students = new ArrayList(); } public void addStudent(Student student) { if (!students.contains(student)) { students.add(student); student.addCourse(this); } } }
13
public class Student { private Map accounts; public Student() { accounts = new HashMap(); } public void addAccount(String accountId, Account account) { accounts.put(accountId, account); } public Account getAccount(String accountId) { return (Account)accounts.get(acccountId); } }
14
Mapping Activities
Optimizing the Object Design Model Mapping Associations Mapping Contracts to Exceptions Mapping Object Models to Tables
Optimizing the Object Design Model: Collapsing an object without interesting behavior Object design model before transformation
Person
SocialSecurity number:String
15
16
Optimizing the Object Design Model: Delaying expensive computations Object design model before transformation
Image filename:String data:byte[] paint()
Account
image 1 0..1
return account; } }
Account
Advertiser
public class Advertiser { private Set accounts;
Account
public class Account { private Advertiser owner; public void setOwner(Advertiser newOwner) { if (owner != newOwner) { Advertiser old = owner; owner = newOwner; if (newOwner != null) newOwner.addAccount(this); if (oldOwner != null) old.removeAccount(this); } } }
public Advertiser() { accounts = new HashSet(); } public void addAccount(Account a) { accounts.add(a); a.setOwner(this); } public void removeAccount(Account a) { accounts.remove(a); a.setOwner(null); } }
* {ordered}
22
Object design model after transformation: 1 class and two binary associations
Statistics +getAverageStat(name) +getTotalStat(name) +updateStats(match) 1 1 Tournament * *
24
Player
Implementing a contract
For each operation in the contract, do the following Check precondition: Check the precondition before the beginning of the method with a test that raises an exception if the precondition is false. Check postcondition: Check the postcondition at the end of the method and raise an exception if the contract is violoated. If more than one postcondition is not satisfied, raise an exception only for the first violation. Check invariant: Check invariants at the same time as postconditions. Deal with inheritance: Encapsulate the checking code for preconditions and postconditions into separate methods that can be called from subclasses.
27
A foreign key is an attribute (or a set of attributes) that references the primary key of another table.
29
30
Buried Association
For one-to-many associations we add the foreign key to the table representing the class on the many end. Associations with multiplicity one can be implemented using a foreign key. Because the association vanishes in the table, we call this a buried association. For all other associations we can select either class at the end of the association.
LeagueOwner
League
Realizing Inheritance
Relational databases do not support inheritance Two possibilities to map UML inheritance relationships to a database schema With a separate table (vertical mapping)
The attributes of the superclass and the subclasses are mapped to different tables
LeagueOwner maxNumLeagues
Player credits
There is no table for the superclass Each subclass is mapped to a table containing the attributes of the subclass and the attributes of the superclass
id 56
33
...
LeagueOwner maxNumLeagues
Player credits
Duplicated columns Modifying the database schema is more complex and error-prone Individual objects are not fragmented across a number of tables, resulting in faster queries