Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.

Slides:



Advertisements
Similar presentations
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Software Engineering September 12, 2001 Capturing.
Advertisements

CSCE 431: From Models to Implementation Some material from Bruegge, Dutoit.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 4, Requirements Elicitation.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Art for Chapter 7, Object Design.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
CEN Ninth Lecture Introduction to Software Engineering (CEN-4010) Instructor: Masoud Sadjadi Object Design.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns (Lecture I)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1 Figure 10-1, Model transformations, refactorings,
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.
Mapping Activities Done By: Sara Al-Khulaifi 11/12/2005.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Conquering Complex and Changing Systems Object-Oriented Software Engineering TJSS System Design Lecture 12 Päivi Ovaska.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns I.
Chapter 7, Object Design.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Implementation Goals: “map” design to clean, efficient code Document any design changes found to be useful Produce code that is correct, modular, understandable,
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.
Chapter 10 Classes Continued
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Object Design  Object design  Detail requirements.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Reuse and Patterns I.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
1 Web Based Programming Section 6 James King 12 August 2003.
Programming Languages and Paradigms Object-Oriented Programming.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Chapter 10, Mapping Models to Code
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 6, System Design Lecture 2.
JavaDoc1 JavaDoc DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY July 24, 2006 by Emil Vassev & Joey Paquet revision 1.2 –
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 4, Requirements Elicitation.
Implementation Goals: “map” design to clean, efficient code Document any design changes found to be useful Produce code that is correct, modular, understandable,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.
Systems Analysis and Design in a Changing World, 3rd Edition
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Software Documentation Section 5.5 ALBING’s Section JIA’s Appendix B JIA’s.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Relational Schema.
Mapping Models to Code. We will skip most of this chapter –It deals with how to go from UML class diagrams to actual code –You should already have a pretty.
Ch- 8. Class Diagrams Class diagrams are the most common diagram found in modeling object- oriented systems. Class diagrams are important not only for.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
Falak Nawaz Mapping Models to Code. Object Model activities 1. Reuse: Identification of existing solutions  Use of inheritance  Off-the-shelf components.
March 1, 2004CS WPI1 CS 509 Design of Software Systems Lecture #6 Monday, March 1, 2004.
CEN Tenth Lecture Introduction to Software Engineering (CEN-4010) Mapping Models to Code Instructor: Masoud Sadjadi
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.
Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.
CEN th Lecture Advance Software Engineering (CEN-5011) Instructor: Masoud Sadjadi Object Design: Specifying.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Two New UML Diagram Types Component Diagram Deployment Diagram.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Bernd Bruegge and Allen Dutoit Requirements Process The requirements process consists of two activities: Requirements Elicitation: Definition of the system.
State of the Art: Model-based Software Engineering
Chapter 10, Mapping Models to Relational Schema
Object-Oriented Database Management System (ODBMS)
Chapter 10, Mapping Models to Code
Chapter 10, Mapping Models to Code
Chapter 10, Mapping Models to Code
Chapter 9, Object Design: Specifying Interfaces
CSCE 606: From Models to Implementation
Chapter 10, Mapping Models to Relational Schema
Advance Software Engineering (CEN-5011)
Presentation transcript:

Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2 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

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3 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.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4 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.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5 Model transformations Source code space Forward engineering Refactoring Reverse engineering Model space Model transformation

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6 Model Transformation Example Object design model before transformation Object design model after transformation: Advertiser + Address Player + Address LeagueOwner + Address PlayerAdvertiserLeagueOwner User + Address

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7 Refactoring Example: Pull Up Field public class Player { private String ; //... } public class LeagueOwner { private String ; //... } public class Advertiser { private String _address; //... } public class User { private String ; } public class Player extends User { //... } public class LeagueOwner extends User { //... } public class Advertiser extends User { //... }

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8 Refactoring Example: Pull Up Constructor Body public class User { private String ; } public class Player extends User { public Player(String ) { this. = ; } public class LeagueOwner extends User{ public LeagueOwner(String ) { this. = ; } public class Advertiser extendsUser{ public Advertiser(String ) { this. = ; } public class User { public User(String ) { this. = ; } } public class Player extends User { public Player(String ) { super( ); } } public class LeagueOwner extends User { public LeagueOwner(String ) { super( ); } } public class Advertiser extends User { public Advertiser(String ) { super( ); } }

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9 Forward Engineering Example public class User { private String ; public String get () { return ; } public void set (String value){ = value; } public void notify(String msg) { //.... } /* Other methods omitted */ } public class LeagueOwner extends User { private int maxNumLeagues; public int getMaxNumLeagues() { return maxNumLeagues; } public void setMaxNumLeagues (int value) { maxNumLeagues = value; } /* Other methods omitted */ } User LeagueOwner +maxNumLeagues:int Object design model before transformation Source code after transformation + String +notify(msg:String)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10 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 11 Collapsing an object without interesting behavior PersonSocialSecurity number:String Person SSN:String Object design model before transformation Object design model after transformation ?

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12 Delaying expensive computations Object design model before transformation Object design model after transformation Image filename:String paint() data:byte[] Image filename:String RealImage data:byte[] ImageProxy filename:String image paint() ?

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13 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 14 Implement Associations  Strategy for implementing associations:  Be as uniform as possible  Individual decision for each association  Example of uniform implementation  1-to-1 association:  Role names are treated like attributes in the classes and translate to references  1-to-many association:  Translate to Vector

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15 Unidirectional 1-to-1 Association Usually this transformation is automatically applied by the CASE tool in the code model

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16 Bidirectional 1-to-1 Association MapAreaZoomInAction 11 MapAreaZoomInAction -targetMap:MapArea-zoomIn:ZoomInAction +getZoomInAction() +setZoomInAction(action) +getTargetMap() +setTargetMap(map) Object design model before transformation Object design model after transformation

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17 1-to-Many Association LayerLayerElement 1* LayerLayerElement -containedIn:Layer-layerElements:Set +elements() +addElement(le) +getLayer() +setLayer(l) +removeElement(le) Object design model beforetransformation Object design model after transformation

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18 Qualification Scenario -runs:Hashtable +elements() +addRun(simname,sr:SimulationRun) +removeRun(simname,sr:SimulationRun) SimulationRun -scenarios:Vector +elements() +addScenario(s:Scenario) +removeScenario(s:Scenario) simname 0..1 * Object design model before transformation Object design model after transformation Scenario SimulationRun

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19 Realization of a unidirectional, one-to-one association AccountAdvertiser 11 Object design model before transformation Source code after transformation 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 20 Bidirectional one-to-one association public class Advertiser { /* The account field is initialized * in the constructor and never * modified. */ private Account account; public Advertiser() { account = new Account(this); } public Account getAccount() { return account; } } Account Advertiser 11 Object design model before transformation Source code after transformation public class Account { /* The owner field is initialized * during the constructor and * never modified. */ private Advertiser owner; 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 21 Bidirectional, one-to-many association public class Advertiser { private Set accounts; 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); } } 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); } } } AdvertiserAccount 1 * Object design model before transformation Source code after transformation

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22 Bidirectional, many-to-many association public class Tournament { private List players; public Tournament() { players = new ArrayList(); } public void addPlayer(Player p) { if (!players.contains(p)) { players.add(p); p.addTournament(this); } public class Player { private List tournaments; public Player() { tournaments = new ArrayList(); } public void addTournament(Tournament t) { if (!tournaments.contains(t)) { tournaments.add(t); t.addPlayer(this); } TournamentPlayer ** Source code after transformation {ordered} Object design model before transformation

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23 Bidirectional qualified association Object design model before forward engineering PlayernickName 0..1 * League Player * * Object design model before transformation League nickName Source code after forward engineering

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24 Bidirectional qualified association (continued) public class League { private Map players; public void addPlayer (String nickName, Player p) { if (!players.containsKey(nickName )) { players.put(nickName, p); p.addLeague(nickName, this); } public class Player { private Map leagues; public void addLeague (String nickName, League l) { if (!leagues.containsKey(l)) { leagues.put(l, nickName); l.addPlayer(nickName, this); } Source code after forward engineering

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25 Transformation of an association class TournamentPlayer ** Object design model before transformation Object design model after transformation: 1 class and two binary associations Statistics +getAverageStat(name) +getTotalStat(name) +updateStats(match) TournamentPlayer ** 11 Statistics +getAverageStat(name) +getTotalStat(name) + updateStats(match)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26 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 27 Exceptions as building blocks for contract violations  Many object-oriented languages, including Java do not include built-in support for contracts.  However, we can use their exception mechanisms as building blocks for signaling and handling contract violations  In Java we use the try-throw-catch mechanism  Example:  Let us assume the acceptPlayer() operation of TournamentControl is invoked with a player who is already part of the Tournament.  In this case acceptPlayer() should throw an exception of type KnownPlayer.  See source code on next slide

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28 The try-throw-catch Mechanism in Java public class TournamentControl { private Tournament tournament; public void addPlayer(Player p) throws KnownPlayerException { if (tournament.isPlayerAccepted(p)) { throw new KnownPlayerException(p); } //... Normal addPlayer behavior } public class TournamentForm { private TournamentControl control; private ArrayList players; public void processPlayerApplications() { // Go through all the players for (Iteration i = players.iterator(); i.hasNext();) { try { // Delegate to the control object. control.addPlayer((Player)i.next()); } catch (KnownPlayerException e) { // If an exception was caught, log it to the console ErrorConsole.log(e.getMessage()); }

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29 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 violated. 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.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30 A complete implementation of the Tournament.addPlayer() contract «precondition» !isPlayerAccepted(p) «invariant» getMaxNumPlayers() > 0 «precondition» getNumPlayers() < getMaxNumPlayers() Tournament +isPlayerAccepted(p:Player):boolean +addPlayer(p:Player) +getMaxNumPlayers():int -maxNumPlayers: int +getNumPlayers():int «postcondition» isPlayerAccepted(p)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31 Heuristics for Mapping Contracts to Exceptions Be pragmatic, if you don’t have enough time.  Omit checking code for postconditions and invariants.  Usually redundant with the code accomplishing the functionality of the class  Not likely to detect many bugs unless written by a separate tester.  Omit the checking code for private and protected methods.  Focus on components with the longest life  Focus on Entity objects, not on boundary objects associated with the user interface.  Reuse constraint checking code.  Many operations have similar preconditions.  Encapsulate constraint checking code into methods so that they can share the same exception classes.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32 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 33 Mapping an object model to a relational database  UML object models can be mapped to relational databases:  Some degradation occurs because all UML constructs must be mapped to a single relational database construct - the table.  UML mappings  Each class is mapped to a table  Each class attribute is mapped onto a column in the table  An instance of a class represents a row in the table  A many-to-many association is mapped into its own table  A one-to-many association is implemented as buried foreign key  Methods are not mapped

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34 Mapping the User class to a database table User +firstName:String +login:String + String id:longfirstName:text[25]login:text[8] text[32] User table

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35 Primary and Foreign Keys  Any set of attributes that could be used to uniquely identify any data record in a relational table is called a candidate key.  The actual candidate key that is used in the application to identify the records is called the primary key.  The primary key of a table is a set of attributes whose values uniquely identify the data records in the table.  A foreign key is an attribute (or a set of attributes) that references the primary key of another table.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36 Example for Primary and Foreign Keys User table Candidate key login firstName “alice” “john” Candidate key Primary key League table login “am384” name “tictactoeNovice” “tictactoeExpert” “js289”“chessNovice” Foreign key referencing User table

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37 Buried Association  Associations with multiplicity one can be implemented using a foreign key.  For one-to-many associations we add a foreign key to the table representing the class on the “many” end.  For all other associations we can select either class at the end of the association.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38 Buried Association League LeagueOwner * 1 id:long LeagueOwner table...owner:long League table...id:long  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 one-to-many associations we add the foreign key to the table representing the class on the “many” end.  For all other associations we can select either class at the end of the association.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39 Another Example for Buried Association Transaction transactionID Portfolio portfolioID... * portfolioID... Portfolio Table transactionID Transaction Table portfolioID Foreign Key

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40 Mapping Many-To-Many Associations City cityName Airport airportCode airportName * * Serves cityName Houston Albany Munich Hamburg City Table airportCode IAH HOU ALB MUC HAM Airport Table airportName Intercontinental Hobby Albany County Munich Airport Hamburg Airport Primary Key cityName Houston Albany Munich Hamburg Serves Table airportCode IAH HOU ALB MUC HAM In this case we need a separate table for the association Separate table for “Serves” association

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41 Mapping the Tournament/Player association as a separate table PlayerTournament ** id Tournament table 23 name... novice 24expert tournamentplayer TournamentPlayerAssociation table Player table id 56 name... alice 79john

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42 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  By duplicating columns (horizontal mapping)  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

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43 Realizing inheritance with a separate table User table id 56 name... zoe 79john role LeagueOwner Player Player User LeagueOwner maxNumLeagues credits name Player table id 79 credits id LeagueOwner table 56 maxNumLeagues... 12

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44 Realizing inheritance by duplicating columns Player User LeagueOwner maxNumLeagues credits name id LeagueOwner table 56 maxNumLeagues name zoe Player table id 79 credits name john

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45 Comparison: Separate Tables vs Duplicated Columns  The trade-off is between modifiability and response time  How likely is a change of the superclass?  What are the performance requirements for queries?  Separate table mapping We can add attributes to the superclass easily by adding a column to the superclass table  Searching for the attributes of an object requires a join operation.  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

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 46 Heuristics for Transformations  For a given transformation use the same tool  If you are using a CASE tool to map associations to code, use the tool to change association multiplicities.  Keep the contracts in the source code, not in the object design model  By keeping the specification as a source code comment, they are more likely to be updated when the source code changes.  Use the same names for the same objects  If the name is changed in the model, change the name in the code and or in the database schema.  Provides traceability among the models  Have a style guide for transformations  By making transformations explicit in a manual, all developers can apply the transformation in the same way.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 47 Documenting the Object Design: The Object Design Document (ODD)  Object design document  Same as RAD +...  … + additions to object, functional and dynamic models (from solution domain)  … + Navigational map for object model  … + Javadoc documentation for all classes

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 48 Criteria for ODD  Restrictiveness  A specification should be precise enough that it excludes unwanted implementations.  Preconditions and postconditions specifying border cases is one way to achieve restrictive specifications.  Generality  A specification, however, should not restrict its implementation.  Clarity  A specification should be easily and unambiguously understandable by developers.  Certain behaviors are more easily described in natura1 language, whereas boundary cases can be described with constraints and exceptions.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 49 Approaches to documenting object design  Self-contained ODD generated from model.  We write and maintain a new UML model using a tool and generate the document automatically. This document would duplicate any application objects identified during analysis.  Disadvantages:  redundancy with the Requirements Analysis Document (RAD)  high level of effort for maintaining consistency with the RAD.  This often leads to an RAD and an ODD that are inaccurate or out of date.  ODD as extension of the RAD  the object design is considered as the set of application objects augmented with solution objects (we add solution objects to the RAD)  Advantage  maintaining consistency between the RAD and the ODD becomes much easier  Disadvantages  Polluting the RAD with information that is irrelevant to the client and the user.  ODD embedded into source code.  We embed the ODD into the source code.  We first represent the ODD using a modeling tool.  Once the ODD becomes stable, we use the modeling tool to generate class stubs. We describe each class interface using tagged comments that distinguish source code comments from object design descriptions.  Once the object design model is documented in the code, we abandon the initial object design model.  Advantage  Consistency between the object design model and the source code

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 50 Embedded ODD approach RAD Document analysis Analysis Analysis model Object design Initial object design model System design Design goals Subsystem decomposition Generate class stubs Initial class stubs ODD Document object design Implementation Commented code

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 51 Documenting Object Design: ODD Conventions  Each subsystem in a system provides a service (see Chapter on System Design)  Describes the set of operations provided by the subsystem  Specifying a service operation as  Signature: Name of operation, fully typed parameter list and return type  Abstract: Describes the operation  Pre: Precondition for calling the operation  Post: Postcondition describing important state after the execution of the operation Use JavaDoc for the specification of service operations.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 52 JavaDoc  Add documentation comments to the source code.  A doc comment consists of characters between /** and */  When JavaDoc parses a doc comment, leading * characters on each line are discarded. First, blanks and tabs preceding the initial * characters are also discarded.  Doc comments may include HTML tags  Example of a doc comment: /** * This is a doc comment */

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 53 More on Java Doc  Doc comments are only recognized when placed immediately before class, interface, constructor, method or field declarations.  When you embed HTML tags within a doc comment, you should not use heading tags such as and, because JavaDoc creates an entire structured document and these structural tags interfere with the formatting of the generated document.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 54 Class and Interface Doc name-text  Creates an “Author” version-text  Creates a “Version” classname  Creates a hyperlink “See Also since-text  Adds a “Since” entry. Usually used to specify that a feature or change exists since the release number of the software specified in the deprecated-text  Adds a comment that this method can no longer be used. Convention is to describe method that serves as replacement  Replaced by setBounds(int, int, int, int).

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 55 Constructor and Method Doc Tags  Can as well parameter-name description Adds a parameter to the "Parameters" section. The description may be continued on the next description Adds a "Returns" section, which contains the description of the return fully-qualified-class-name description Adds a "Throws" section, which contains the name of the exception that may be thrown by the method. The exception is linked to its class classname Adds a hyperlink "See Also" entry to the method.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 56 Example: Specifying a Service in Java /** Office is a physical structure in a building. It is possible to create an instance of a office; add an occupant; get the name and the number of occupants */ public class Office { /** Adds an occupant to the office */ NAME name is a nonempty string */ public void AddOccupant(string name); Returns the name of the office. Requires, that Office has been initialized with a name */ public string GetName();.... }

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 57 Summary  Undisciplined changes => degradation of the system model  We reviewed model transformation and forward engineering techniques:  Optiziming the class model  Mapping associations to collections  Mapping contracts to exceptions  Mapping class model to storage schemas