上降文通大学 SHANGHAI JLAO TONG UNIVERSITY 10.Mapping Models to Code 漏 WnnmM 泰 SHANG 1日gG
10. Mapping Models to Code
上游充通大兽 Outline SHANGHAI JIAO TONG UNIVERSITY Overview 国Mapping Concepts ④Mapping Activities Case Study Software Engineering
Software Engineering Outline Overview Mapping Concepts Mapping Activities Case Study
上游充通大兽 1.Overview SHANGHAI JIAO TONG UNIVERSITY Object design is situated between system design and implementation.Object design is not very well understood and if not well done,leads to a bad system implementation. In this lecture,we describe a selection of transformations to illustrate a disciplined approach to implementation to avoid system degradation. 1.Operations on the object model: Optimizations to address performance requirements 2.Implementation of class model components: Realization of associations Realization of operation contracts 3.Realizing entity objects based on selected storage strategy Mapping the class model to a storage schema Software Engineering
Software Engineering 1. Overview Object design is situated between system design and implementation. Object design is not very well understood and if not well done, leads to a bad system implementation. In this lecture, we describe a selection of transformations to illustrate a disciplined approach to implementation to avoid system degradation. 1. Operations on the object model: • Optimizations to address performance requirements 2. Implementation of class model components: • Realization of associations • Realization of operation contracts 3. Realizing entity objects based on selected storage strategy • Mapping the class model to a storage schema
上游究通大粤 Characteristics of Object Design Activities SHANGHAI JIAO TONG UNIVERSITY Developers perform transformations to the object model to improve its modularity and performance. Developers transform the associations of the object model into collections of object references,because programming languages do not support the concept of association. If the programming language does not support contracts,the developer needs to write code for detecting and handling contract violations. Developers often revise the interface specification to accommodate new requirements from the client. All these activities are intellectually not challenging However,they have a repetitive and mechanical flavor that makes them error prone. Software Engineering
Software Engineering Characteristics of Object Design Activities Developers perform transformations to the object model to improve its modularity and performance. Developers transform the associations of the object model into collections of object references, because programming languages do not support the concept of association. If the programming language does not support contracts, the developer needs to write code for detecting and handling contract violations. Developers often revise the interface specification to accommodate new requirements from the client. All these activities are intellectually not challenging • However, they have a repetitive and mechanical flavor that makes them error prone
上游充通大粤 SHANGHAI JIAO TONG UNIVERSITY 2.Mapping Concepts Software Engineering
Software Engineering 2. Mapping Concepts
上游充通大学 2.1 State of the Art of Model-based Software SHANGHAI JIAO TONG UNIVERSITY Engineering The Vision During object design we would like to implement a system that realizes the use cases specified during requirements elicitation and system design. The Reality Different developers usually handle contract violations differently. Undocumented parameters are often added to the API to address a requirement change. Additional attributes are usually added to the object model,but are not handled by the persistent data management system, possibly because of a miscommunication. Many improvised code changes and workarounds that eventually yield to the degradation of the system. Software Engineering
Software Engineering 2.1 State of the Art of Model-based Software Engineering The Vision • During object design we would like to implement a system that realizes the use cases specified during requirements elicitation and system design. The Reality • Different developers usually handle contract violations differently. • Undocumented parameters are often added to the API to address a requirement change. • Additional attributes are usually added to the object model, but are not handled by the persistent data management system, possibly because of a miscommunication. • Many improvised code changes and workarounds that eventually yield to the degradation of the system
上游充通大学 2.2 Model transformations SHANGHAI JIAO TONG UNIVERSITY Forward engineering Refactoring Model transformation Reverse engineering Model space Source code space Software Engineering
Software Engineering 2.2 Model transformations Source code space Forward engineering Refactoring Reverse engineering Model space Model transformation
上克通大¥2.3 Model Transformation Example SHANGHAI JIAO TONG UNIVERSITY Object design model before transformation LeagueOwner Advertiser Player +email:Address email:Address +emai1 Address Object design model after transformation: User +email:Address LeagueOwner Advertiser Player Software Engineering
Software Engineering 2.3 Model Transformation Example Object design model before transformation Object design model after transformation: Advertiser +email:Address Player +email:Address LeagueOwner +email:Address LeagueOwner Advertiser Player User +email:Address
上通大Refactoring Example:Pull Up Field SHANGHAI JIAO TONG UNIVERSITY public class User private String email; public class Player extends public class Player User private String email; //... //... 3 3 public class LeagueOwner public class LeagueOwner extends User private String eMail; //... //... 3 3 public class Advertiser public class Advertiser extends User private String //... email_address; 3 //... } Software Engineering
Software Engineering Refactoring Example: Pull Up Field public class Player { private String email; //... } public class LeagueOwner { private String eMail; //... } public class Advertiser { private String email_address; //... } public class User { private String email; } public class Player extends User { //... } public class LeagueOwner extends User { //... } public class Advertiser extends User { //... }
上游充通大学 Refactoring Example:Pull Up Constructor SHANGHAI JIAO TONG UNIVERSITY Body public class User public class User private String email; public User(String email) this.email email; public class Player extends User 3 public class Player extends User public Player(String email){ this.email email; public Player(String email){ super(ema11); publ ic class LeagueOwner extends 3 eagueOwner(String Usert publ ic class LeagueOwner extends this.email email; User t 3 mieagueOwner(String 3 super(email); public class Adyertiser 3 extendsUser{ iAdvertiser(String this.email email; publ ic class Advertiser extends User t 3 dvertiser(String super(email); Software Engineering
Software Engineering Refactoring Example: Pull Up Constructor Body public class User { private String email; } public class Player extends User { public Player(String email) { this.email = email; } } public class LeagueOwner extends User{ public LeagueOwner(String email) { this.email = email; } } public class Advertiser extendsUser{ public Advertiser(String email) { this.email = email; } } public class User { public User(String email) { this.email = email; } } public class Player extends User { public Player(String email) { super(email); } } public class LeagueOwner extends User { public LeagueOwner(String email) { super(email); } } public class Advertiser extends User { public Advertiser(String email) { super(email); } }