• Ingen resultater fundet

Software Engineering I (02161) Week 7 Assoc. Prof. Hubert Baumeister

N/A
N/A
Info
Hent
Protected

Academic year: 2022

Del "Software Engineering I (02161) Week 7 Assoc. Prof. Hubert Baumeister"

Copied!
47
0
0

Indlæser.... (se fuldtekst nu)

Hele teksten

(1)

Software Engineering I (02161)

Week 7

Assoc. Prof. Hubert Baumeister

DTU Compute Technical University of Denmark

Spring 2018

(2)

Contents

Sequence Diagrams

Object-orientation: Centralized vs Decentralized Control/Computation From Requirements to Design: CRC Cards

Standup Meetings

(3)

Sequence Diagram: Computing the price of an order

I

Class diagram

Order calculate price calculate base price calculate discounts

Product name

price

Customer name

discount info

OrderLine quantity

*

1 1

I

Problem:

I

What are the operations doing?

(4)

Sequence diagram

(5)

Creation and Deletion of objects

(6)

Synchronous– vs Asynchronous Calls:

Synchronous

b.m(4);

c.n(...) // Starts after m has returned

Synchronous calls

m(4)

n(...)

a:A b:B c:C

Asynchronous

// (new Thread(){ public void run() {b.m(4);}}).start();

new Thread(() -> {b.m(4);}).start(); // Using Lambdas from Java 8 c.n(...) // Starts immediately after m has been called

(7)

Synchronous– vs Asynchronous Calls:

Synchronous

b.m(4);

c.n(...) // Starts after m has returned

Synchronous calls

m(4)

n(...)

a:A b:B c:C

Asynchronous

// (new Thread(){ public void run() {b.m(4);}}).start();

new Thread(() -> {b.m(4);}).start(); // Using Lambdas from Java 8 c.n(...) // Starts immediately after m has been called

Asynchronous calls

m(4) n(...)

a:A b:B c:C

(8)

Interaction Frames Example

Realising an algorithm using a sequence diagram public void dispatch() {

for (LineItem lineItem : lineItems) { if (lineItem.getValue() > 10000) {

careful.dispatch();

} else {

regular.dispatch();

} }

if (needsConfirmation()) { messenger.confirm();

}

}

(9)

Realisation with Interaction Frames

(10)

Interaction Frame Operators I

(11)

Interaction Diagrams

Interaction Diagrams = Sequence + Communication Diagrams Sequence Diagram

Communication Diagram

(12)

Interaction Diagrams

Interaction Diagrams = Sequence + Communication Diagrams Sequence Diagram

Communication Diagram

(13)

Usages of sequence diagrams

I

Show the exchange of messages of a system

I

i.e. show the execution of the system

I

in general only, one scenario

I

with the help of interaction frames also several scenarios

I

For example use sequence diagrams for

I

Designing (c.f. CRC cards)

I

Visualizing program behaviour

(14)

Exercise: MarriageAgency Sequence Diagram

Customer sex:String birthYear:int interests:String[*]

match(c:Customer) hasOppositeSex(c) hasAppropriateAgeDifference(c) hasOneInterestInCommon(c) MarriageAgency

matchCustomer(c):Customer[*] *

public List<Customer> matchCustomer(c) {

List<Customer> matches = new ArrayList<Customer>();

for (Customer candidate : customers) { if (c.match(candidate)) {

matches.add(candidate);

return candidate;} }public class Customer {

...public bool match(Customer c) { return c.hasOppositeSex(this); } public bool hasOppositeSex(Customer c) {

return getSex() != c.getSex();

}public String getSex() { return sex; } }

MatchCustomer Sequence Diagram: one matching candidate

(15)

Solution: One execution

sd

matchCustomer(c)

new match(cand)

hasOppositeSex(cand)

getSex()

getSex()

add(cand) User

: MarriageAgency c : Customer cand : Customer

ms : List<Customer>

(16)

Solution: Several executions (with Interaction Frames)

sd

matchCustomer(c)

match(cand)

hasOppositeSex(cand)

getSex()

getSex()

add(cand) opt: if match

loop: for all candidates User

: MarriageAgency c : Customer cand : Customer

ms : List<Customer>

(17)

Contents

Sequence Diagrams

Object-orientation: Centralized vs Decentralized Control/Computation From Requirements to Design: CRC Cards

Standup Meetings

(18)

Centralized control

Order calculate price calculate base price calculate discounts

Product name

price

Customer name

discount info

OrderLine quantity

*

1

1

(19)

Centralised control

(20)

Distributed control

(21)

Distributed Control: Class diagram

OrderLine quantity calculate price

Customer name

discount info calculate discount

Product name

price

getPrice(quantity:int) Order

calculate price calculate base price calculate discounts

1

1

*

(22)

Centralized vs Distributed control

I

Centralized control

I

One method

I

Data objects

! procedural programming language

I

Distributed control

I

Objects collaborate

I

Objects = data and behaviour

! Object-orientation

I

Advantage

I

Easy to adapt

! Design for change

(23)

Design for Change

How to add a new type of product, which is cheaper in large quantities?

OrderLine quantity calculate price

Customer name discount info calculate discount

Product name price

getPrice(quantity:int) Order

calculate price calculate base price calculate discounts

1

1 *

(24)

Design for Change

How to add a new type of product, which is cheaper in large quantities?

sd: Order calculateOrder

calculateOrder

calculatePrice

getPrice(n)

calculatePrice

getPrice(n)

getDiscountValue(o) getBaseValue User

Order OrderLine Product BulkProduct Customer

(25)

Contents

Sequence Diagrams

Object-orientation: Centralized vs Decentralized Control/Computation From Requirements to Design: CRC Cards

Standup Meetings

(26)

From Requirements to Design

Design process (abstract)

1 Choose a set of user stories to implement 2 Select the user story with the highest priority

a Design the system by executing the user story in your head

!

e.g. use CRC cards for this

b Extend an existing class diagram with classes, attributes, and methods

c Create acceptance tests

d Implement the user story test-driven, creating tests as necessary and guided by your design

3 Repeat step 2 with the user story with the next highest

priority

(27)

Introduction CRC Cards

I

Class Responsibility Collaboration

I

Developed in the 80’s

I

Used to

I

Analyse a problem domain

I

Discover object-oriented design

I

Teach object-oriented design

I

Object-oriented design:

I

Objects have state and behaviour

I

Objects delegate responsibilities

I

”Think objects”

(28)

CRC Card Template

A larger example

I

http://c2.com/doc/crc/draw.html

(29)

Process

I

Basic: Simulate the execution of use case scenarios / user stories

I

Steps

1. Brainstorm classes/objects/components

2. Assign classes/objects/components to persons (group up to 6 people)

4. Execute the scenarios one by one

a) add new classes/objects/components as needed b) add new responsibilities

c) delegate to other classes / persons

(30)

Library Example: Use Case Diagram

search for book return book borrow book LibrarySystem

User

(31)

Library Example: Detailed Use Case

Feature: Borrow Book

Description: The user borrows a book Actors: User

Scenario: User borrows book

Given a book with signature "Beck99" is in the library And a user is registered with the library

When the user borrows the book Then the book is borrowed by the user

Scenario: User borrows book more than 10 books Given a registered user has borrowed 10 books When the user borrows another book

Then the book is not borrowed by the user

And the error message is "Can’t borrow more than 10 books"

Scenario: User cannot borrow books if he has overdue books Given a registered user has an overdue book

When the user borrows another book Then the book is not borrowed by the user

And the error message is "Can’t borrow book if user has overdue books"

...

(32)

Example

I

Set of initial CRC cards: Library Application, User, Book

I

Use case Borrow Book main scenario (user story)

I

”What happens when Barbara Stewart, who has no

accrued fines and one outstanding book, not overdue,

borrows the book entitled Extreme Programming”

(33)

Borrow Books: CRC cards

(34)

Borrow Books: CRC cards

(35)

Borrow Books: CRC cards

(36)

Borrow Books: CRC cards

(37)

Borrow Books: Class and Sequence Diagrams

Book LibraryApplication

borrowBook(User, Book)

User borrowBook(Book)

* borrowedBooks

Borrow Book

borrowBook(u,b)

borrowBook(b) Library User

l : Library

Application u : User

(38)

More than 10 books: CRC cards

(39)

More than 10 books: Class and Sequence Diagrams

Book LibraryApplication

borrowBook(User, Book)

User borrowBook(Book) canBorrow()

* borrowedBooks

Borrow Book

borrowBook(u,b)

borrowBook(b)

canBorrow Library User

l : Library Application u : User

(40)

Overdue books: CRC cards

(41)

Overdue books: CRC cards

(42)

Overdue books: CRC cards

(43)

Overdue books: CRC cards

(44)

Overdue books: Class and Sequence Diagrams

Book dueDate : Date isOverdue() LibraryApplication

getCurrentDate() borrowBook(User, Book)

User borrowBook(Book) canBorrow()

* borrowedBooks

Borrow Book

borrowBook(u,b1)

borrowBook(b1,d)

canBorrow()

setDueDate(d)

borrowBook(u,b)

borrowBook(b,d1)

canBorrow(d1) isOverdue(d1)

true

"Has Overdue Books"

Library User

l : Library Application u : User b1 : Book

(45)

Contents

Sequence Diagrams

Object-orientation: Centralized vs Decentralized Control/Computation From Requirements to Design: CRC Cards

Standup Meetings

(46)

Standup Meetings (XP practice)

I

Short meetings: hence standing

I

Called ”Daily Scrum” in Scrum

I

Set the context of the day:

I

First round:

I

What did each developer do last time?

I

Second round:

I

What does the developer plan to do today?

I

Third round:

I

What are any obstacles to his work?

I

Overview only

I

More discussions needed ! separate meeting

! You should do these meetings every time you meet

(47)

Status meetings (in this course)

I

3 x 10–15min meetings for each group

I

Each meeting two weeks apart

I

Questions to be discussed

I

Show what did the group do last

I

What does the group plan to do next?

I

What are any obstacles to the work of the group?

Referencer

RELATEREDE DOKUMENTER

Software Development Process (cont.) From Requirements to Design: CRC Cards Version control... Resource

I new velocity: story points of finished user stories per iteration. → What can be done in the

Scenario: Buy a fruit with enough money Given the vending machine has fruits. When the user enters enough money for a fruit And the user selects

Travel Agency functional requirements: System use cases Part I: manage trip.. Travel Agency functional requirements: System use cases Part II:

Software Testing (JUnit, Test Driven Development, Systematic Tests, Code Coverage). System Modelling (mainly based on

Software Testing (JUnit, Test Driven Development, Systematic Tests, Code Coverage). System Modelling (mainly based on

I Design Patterns: Intent, Motiviation, Applicability, Structure, Participants, Collaborations, Consequences, Implementation, Sample Code, Known Uses, Related Patterns..

With the two books dealing with localisation by Pym (2004) and Esselink (2000) and the book chapter by Esselink (2003), the concept of localisation is defi ned, exemplifi ed