P2: Exercise 2 Discussion -...
Transcript of P2: Exercise 2 Discussion -...
![Page 1: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/1.jpg)
P2: Exercise 2 Discussion
Yannik Dällenbach
8 March 2019
!1
![Page 2: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/2.jpg)
Exercise 2
SkipPlayer: Skip the next player’s turn? • Main problem: Find the next player
Approaches• Use boolean flag• Use an ArrayList to get random index• (…more advanced / dynamic solutions possible)
!2
![Page 3: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/3.jpg)
ScrambleUp
ScrambleUp: How to get a random player?• Main problem: Find a random player and exchange.
!3
![Page 4: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/4.jpg)
ScrambleUp
public ISquare landHereOrGoHome() { if (this.isOccupied()) { return game.firstSquare(); } randomPlayer = game.getRandomPlayer();
// … int position = randomPlayer.position();
// …
return game.getSquare(position); }
!4
![Page 5: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/5.jpg)
JavaDoc: Examples
/** * Square that swaps player that landed on it with another * random player. */ public class ScrambleUp extends Square implements ISquare {
// … }
!5
Missing details
![Page 6: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/6.jpg)
JavaDoc: Examples
/** * The class ScrambleUp contains methods for swapping * a player landing on it with another random player. */ public class ScrambleUp extends Square implements ISquare {
// … }
!6
Filler words: „The class ScrambleUp“
![Page 7: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/7.jpg)
JavaDoc: Examples
/** * Swaps entering player with another random selected player. * * Is created and called inside the {@link Game} class. * Extends {@link Square}. * * If there is only one player left in the game, the player * will not swapped. */ public class ScrambleUp extends Square implements ISquare {
// … }
!7
Better
![Page 8: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/8.jpg)
Git
These are not good commit messages:
• No more errors!• I hate git• FIRST TRY• V3• slooowly getting there• …
![Page 9: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/9.jpg)
Git
These are better:
Implemented SwapSquare
Implemented landHereOrGoHome to exchange the current with another random player. Overrides toString method
!9
![Page 10: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/10.jpg)
Design by Contract, Assertions, and Exceptions
!1 0
![Page 11: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/11.jpg)
Exception or Assertion?
/** * Sets the refresh rate for the current display. * @param rate new refresh rate */ public void setRefreshRate(int rate) {
// what if rate < 0? }
!1 1
![Page 12: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/12.jpg)
Exception or Assertion?
/** * Sets the refresh rate for the current display. * @param rate new refresh rate, must be >= 0 */ public void setRefreshRate(int rate) {
assert rate >= 0; }
!1 2
![Page 13: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/13.jpg)
Exception or Assertion?
/** * Sets the refresh rate for the current display. * @param rate new refresh rate * @throws IllegalArgumentException if rate is not valid */ public void setRefreshRate(int rate)
throws IllegalArgumentException { if (rate < 0) {
throw new IllegalArgumentException(); }
}
!1 3
![Page 14: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/14.jpg)
Assertions
• Use when you expect a property to hold
• Use for contracts• Pre-/postconditions, invariants
• Use inside complex code• For example in an algorithm to make sure an intermediate result
holds
!1 4
![Page 15: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/15.jpg)
Assertions
/** * Draw a vertical line, starting from position, * with a length of steps + 1. * * @param position start location of the line, must not be null * @param steps length of the line */ public void drawVertical(Point position, int steps) {
assert position != null; // Implementation omitted assert(invariant());
}
!1 5
![Page 16: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/16.jpg)
Assertions
• Favor assertions/preconditions for checking method parameters in private/internal API • Senders come from within your project => go fix the bug!• Simplifies design
• Use assertions for postconditions and invariants
!1 6
![Page 17: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/17.jpg)
Exceptions
• Error handling• Expected behavior
• Deal with it in try-catch blocks, or• throw it up to the caller
!1 7
public void matches(String filename) throws NotImplementedException {
throw new NotImplementedException();
}
![Page 18: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/18.jpg)
Exceptions
Do not abuse exceptions
!1 8
try { int index = 0; while (true) {
players[index++] = new Player(); }
} catch (ArrayIndexOutOfBoundsException e) {}
![Page 19: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/19.jpg)
Exceptions
Do not abuse exceptions
!1 9
for (int i = 0; i < players.length; i++) { players[i] = new Player();
}
![Page 20: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/20.jpg)
Exceptions
• Favor exceptions for checking method parameters in public/external API
• Can’t trust user to read JavaDoc
• Always use exceptions to check user input!
!2 0
![Page 21: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/21.jpg)
Checked and Unchecked Exceptions
• Checked exceptions must either be declared
!2 1
• or wrapped inside a try-catch block
• Use checked exceptions unless you have a very good reason not to!
public void fooBar() throws TodoException { /* … */}
public void fooBar() { try {
// something that throws a TodoException } catch (TodoException e) {
// handle exception }
}
![Page 22: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/22.jpg)
NullPointerException
• Very common unchecked exception
• Often hard to tell where it came from• Value may be passed around for a while before it is used
=> Include null checks where appropriate
!2 2
![Page 23: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/23.jpg)
NullPointerException
private void newGame() { setPlayer(null); execute();
}
private void setPlayer(Player player) { this.player = player;
}
private void execute() { this.player.move();
}
!2 3
![Page 24: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/24.jpg)
NullPointerException
private void newGame() { setPlayer(null); execute();
}
private void setPlayer(Player player) { this.player = player;
}
private void execute() { this.player.move();
}
!2 4
Exception in thread "main" java.lang.NullPointerException at exercise_03.SomeClass.execute(SomeClass.java:79)at exercise_03.SomeClass.newGame(SomeClass.java:65)at exercise_03.SomeClass.main(SomeClass.java:7) ... Process finished with exit code 1
Why is player == null here?
![Page 25: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/25.jpg)
NullPointerException
private void newGame() { setPlayer(null); execute();
}
/** @param player must not be null */ private void setPlayer(Player player) {
assert player != null; this.player = player;
}
private void execute() { this.player.move();
}
!2 5
Exception in thread "main" java.lang.AssertionError at exercise_03.SomeClass.setPlayer(SomeClass.java:74)at exercise_03.SomeClass.newGame(SomeClass.java:64)at exercise_03.SomeClass.main(SomeClass.java:7)Process finished with exit code
![Page 26: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/26.jpg)
Another example
/** * Look up the object at the top of * this stack and return it. * * @return the object at the top */ public E top() {
return top.item; }
!2 6
What if the stack is empty?
![Page 27: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/27.jpg)
Another example
/** * Look up the object at the top of * this stack and return it. * Returns null if called on an empty stack. * * @return the object at the top */ public E top() {
if (this.isEmpty()) { return null;
} return top.item;
}
!2 7
What if the stack contains null values?
![Page 28: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/28.jpg)
Another example
/** * Look up the object at the top of * this stack and return it. * @throws EmptyStackException if the stack is empty * * @return the object at the top */ public E top() throws EmptyStackException {
if (this.isEmpty()) { throw new EmptyStackException();
} return top.item;
}
!2 8
👌
![Page 29: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/29.jpg)
Exercise 3
!2 9
![Page 30: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/30.jpg)
Turtle Game
Demo
!3 0
![Page 31: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/31.jpg)
Turtle Game
• A turtle that moves around a 50x50 board• Move left, right, up, down or jump• Leave a red trail
• Input: String representing a turtle program
right 5 down 4 left 3 jump 20 20 down 10
!3 1
![Page 32: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/32.jpg)
Turtle Game
• You start with• TurtleRenderer: GUI• BoardMaker: Class that gets text from GUI and returns a
boolean array of size 50x50
• You implement• Parse input program (split lines into commands)• Execute turtle actions• Keep track of trail
!3 2
As always: git pull p2-exercises masterRead exercise_03.md
![Page 33: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/33.jpg)
Introduction to UMLMathias Stocker
![Page 34: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/34.jpg)
Main areas of application
•Documentation•Drafts
34
![Page 35: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/35.jpg)
Documentation
•Can be done automatically•Can be an «overkill»
35
![Page 36: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/36.jpg)
Documentation
source: java-player.sourceforge.net
36
![Page 37: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/37.jpg)
A draft helps you to…
… simplify reality… unterstanding an existing solution… deciding how to build something from scratch… capture requirements and discuss your idea with others… reduce your effort to test different approaches
37
![Page 38: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/38.jpg)
structureclass diagram
component diagram
composite structure diagram
object diagram
package diagram
profile diagram
behaviouractivity diagram
comunication diagram
interaction overview diagram
sequence diagram
state machine diagram
timing diagram
Modeling your system…
38
![Page 39: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/39.jpg)
structureclass diagram
component diagram
composite structure diagram
object diagram
package diagram
profile diagram
behaviouractivity diagram
comunication diagram
interaction overview diagram
sequence diagram
state machine diagram
timing diagram
Modeling your system…
39
![Page 40: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/40.jpg)
Class diagram
40
![Page 41: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/41.jpg)
Classes and Interfaces
41
![Page 42: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/42.jpg)
Classes and Interfaces
Access modifiers+ public, - private, # protected, static
AttributesacessIdentifier : typeExample: - size: int
MethodsaccessIdentifier(parameter: type): returnType
42
![Page 43: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/43.jpg)
Implementation and extension
43
![Page 44: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/44.jpg)
Dependency
44
![Page 45: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/45.jpg)
Aggregation vs. Composition
45
![Page 46: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/46.jpg)
Sequence diagram
46
![Page 47: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/47.jpg)
Sequence diagram
47
![Page 48: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/48.jpg)
Sequence diagram
48
![Page 49: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/49.jpg)
Keep in mind
• Different aspects, different diagram type• Keep it simple• Focus on what you want to communicate, forget the
rest
49
![Page 50: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/50.jpg)
On paper: Not enough information
50
![Page 51: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/51.jpg)
On paper: Too much information
51
![Page 52: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/52.jpg)
On paper
52
![Page 53: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/53.jpg)
Exercise 3
Use the information from the lecture and from this presentation to solve the UML related tasks in Exercise 3
Add both diagrams in a common format (e.g. JPG, PDF) to the exercise root in your group folder.
If you do not have a scanner, you can just take a photo of the UML diagrams with a smartphone.
53
![Page 54: P2: Exercise 2 Discussion - scg.unibe.chscg.unibe.ch/download/lectures/p2lab/19-03-08-week_03-Assertions_DbC... · Exercise 2 SkipPlayer: Skip the next player’s turn? • Main problem:](https://reader030.fdocuments.us/reader030/viewer/2022040717/5e22b43464c6470e74075db0/html5/thumbnails/54.jpg)
To learn more
• http://scg.unibe.ch/teaching/p2/ (P2 reading material, UML Reference)
• Book: UML Distilled, Martin Fowler
54