Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mapping Activities Done By: Sara Al-Khulaifi 11/12/2005.

Similar presentations


Presentation on theme: "Mapping Activities Done By: Sara Al-Khulaifi 11/12/2005."— Presentation transcript:

1 Mapping Activities Done By: Sara Al-Khulaifi 11/12/2005

2 Outlines * Introduction *Mapping Activities. -Optimizing the Object Design Model -Mapping Associations -Mapping Contracts to Exceptions -Mapping Object Models to Tables *Conclusion

3 Introduction We need a selection of transformations to illustrate a disciplined approach to implementation to avoid system degradation. Object Design System Design Implementation

4 Mapping Activities Optimizing the Object Design Model Mapping Associations Mapping Contracts to Exceptions Mapping Object Models to Tables

5 Optimizing the Object Design Model *Direct translation of an analysis model into source code is often inefficient. *During object design, we transfer object model to meet the design goals identified during system design.

6 Common Optimizations: 1. Adding associations to optimize access paths. 2. Collapsing objects into attributes. 3. Delaying expensive computations. 4. Caching the results of expensive computations.

7 Optimizing Access paths “ Common sources of inefficiency are: *Repeated association traversals. *”Many” associations. *Misplaced attributes.”

8 Collapsing an object without interesting behavior PersonSocialSecurity number:String Person SSN:String Object design model before transformation Object design model after transformation ?

9 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 10..1 paint() ?

10 Caching the result of expensive computations *Some methods are called many times, but their results are based on values that do not change or change frequently. *Reducing the number of computations required by these methods substantially improve overall response time. *Example: LeagueBoundary.getStatistics()

11 We had discus Optimizing the Object Design Model  Mapping Associations Mapping Contracts to Exceptions Mapping Object Models to Tables

12 Mapping Associations to Collections *Associations are UML concepts that denote collections of bidirectional links between two or more objects. *OOPL uses references instead of associations. References are unidirectional and take place between two objects. During object design we realize associations in terms of references.

13 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

14 Unidirectional 1-to-1 Association Usually this transformation is automatically applied by the CASE tool in the code model

15 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

16 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

17 many-to-many association Source code after transformation 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

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

19 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)

20 Optimizing the Object Design Model Mapping Associations  Mapping Contracts to Exceptions Mapping Object Models to Tables

21 Mapping Contracts to Exceptions 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.

22 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()); }

23 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)

24 Simple mapping *Checking Preconditions. *Checking Postconditions. *Checking invariant *Dealing with inheritance. *Coding effort. *Increased opportunities. *Obfuscated code. *Performance drawback.

25 Optimizing the Object Design Model Mapping Associations Mapping Contracts to Exceptions (*)Mapping Object Models to Tables

26 Questions: (1) List the four Mapping Activities. (2)What are the common source of inefficiency? (3)What is a reference? And what is a collections? (4)Why do we use Qualified associations? (5)When do we apply check preconditions?

27 Thanx 4 U’R Attention Sara Al-Khulaifi


Download ppt "Mapping Activities Done By: Sara Al-Khulaifi 11/12/2005."

Similar presentations


Ads by Google