Using UML Patterns and Java Object Oriented Software Engineering Chapter 10 Mapping Models to Code Overview Operations on the object model Optimizations to address performance requirements Implementation of class model components Realization of associations Realization of operation contracts Self reading Realizing entity objects based on selected storage strategy Mapping the class model to a storage schema Bernd Bruegge Allen H Dutoit Object Oriented Software Engineering Using UML Patterns and Java 2 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 Self reading In C In Java 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 Bernd Bruegge Allen H Dutoit Object Oriented Software Engineering Using UML Patterns and Java 3 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 Recall our discussion 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 And lack of traceability Many improvised code changes and workarounds are made ad hoc which eventually leads to a severe degradation of the system Bernd Bruegge Allen H Dutoit Object Oriented Software Engineering Using UML Patterns and Java 4 Model transformations Forward engineering Refactoring Model transformation Reverse engineering Model space Source code space 1 1 mapping Bernd Bruegge Allen H Dutoit Object Oriented Software Engineering Using UML Patterns and Java 5 Model Transformation Example Object design model before transformation LeagueOwner email Address Object design model after transformation Player Advertiser email Address email Address User email Address LeagueOwner Bernd Bruegge Allen H Dutoit Advertiser Object Oriented Software Engineering Using UML Patterns and Java Player 6 Refactoring Example Pull Up Field public class User private String email public class Player private String email public class LeagueOwner private String eMail public class Advertiser private String email address Bernd Bruegge Allen H Dutoit public class Player extends User public class LeagueOwner extends User public class Advertiser extends User Object Oriented Software Engineering Using UML Patterns and Java 7 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 Player String email public class Player extends User this email email public Player String email super email public class LeagueOwner extends User public LeagueOwner String email this email email public class LeagueOwner extends User public LeagueOwner String email super email Bernd Bruegge Allen H Dutoit Object Oriented Software Engineering Using UML Patterns and Java 8 Other Mapping Activities Optimizing the Object Design Model Collapsing objects Delaying expensive computations Mapping Associations Mapping Contracts to Exceptions Self Mapping Object Models to Tables Bernd Bruegge Allen H Dutoit reading Object Oriented Software Engineering Using UML Patterns and Java 9 Collapsing an object without interesting behavior Object design model before transformation Person SocialSecurity number String Object design model after transformation Person SSN String Bernd Bruegge Allen H Dutoit Object Oriented Software Engineering Using UML Patterns and Java 10 Self reading Delaying expensive computations Object design model before transformation Image filename String data byte paint Object design model after transformation Image filename String paint A good model Proxy Pattern ImageProxy filename String paint Bernd Bruegge Allen H Dutoit image 1 0 1 RealImage data byte paint Object Oriented Software Engineering Using UML Patterns and Java 11 Other Mapping Activities Optimizing the Object Design Model 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 12 Realization of a unidirectional one to one association Which direction Object design model before transformation Advertiser 1 1 Source code after transformation Account Role name public class Advertiser private Account account public Advertiser account new Account public Account getAccount return account Bernd Bruegge Allen H Dutoit Object Oriented Software Engineering Using UML Patterns and Java 13 Bidirectional one to one association Object design model before transformation 1 Advertiser 1 Source code after transformation public class Advertiser The account field is initialized in the constructor and never modified private Account account Account Role name public class Account The owner field is initialized during the constructor and never modified private Advertiser owner public Advertiser account new Account this public Account getAccount return account public Account owner Advertiser this owner owner public Advertiser getOwner return owner Bernd Bruegge Allen H Dutoit Object Oriented Software Engineering Using UML Patterns and Java 14 Bidirectional one to many association Object design model before transformation 1 Advertiser Source code after transformation Account constructor public class Account private Advertiser owner public void setOwner Advertiser newOwner public Advertiser accounts new HashSet if owner newOwner Advertiser old owner public void addAccount Account a owner newOwner accounts add a if newOwner null a setOwner this newOwner addAccount this if oldOwner null public void removeAccount Account a old removeAccount this accounts remove a a setOwner null public class Advertiser private Set
View Full Document
Unlocking...