02291: System Integration Week 4 Hubert Baumeister huba@dtu.dk - - PowerPoint PPT Presentation

02291 system integration
SMART_READER_LITE
LIVE PREVIEW

02291: System Integration Week 4 Hubert Baumeister huba@dtu.dk - - PowerPoint PPT Presentation

02291: System Integration Week 4 Hubert Baumeister huba@dtu.dk DTU Compute Technical University of Denmark Spring 2018 Contents From Requirements to Design CRC Cards Components (part Ia) Object-orientation: Centralized vs Decentralized


slide-1
SLIDE 1

02291: System Integration

Week 4 Hubert Baumeister

huba@dtu.dk

DTU Compute Technical University of Denmark

Spring 2018

slide-2
SLIDE 2

Contents

From Requirements to Design CRC Cards Components (part Ia) Object-orientation: Centralized vs Decentralized Control/Computation Summary

slide-3
SLIDE 3

From Requirements to Design

Problem

◮ Given a requirements model consisting of:

1 use case diagram 2 detailed use case descriptions 3 glossary 4 non functional requirements

◮ how do I get a system design consisting of

a component diagram b class diagram c behaviour design

slide-4
SLIDE 4

From Requirements to Design: Solution

◮ Design process

1 Define the basic architecture of the system 2 The terms in the glossary give first candidates for classes, attributes, and operations 3 Realize one use case scenario / user story at a time

→ simulate execution → CRC cards

slide-5
SLIDE 5

Contents

From Requirements to Design CRC Cards Components (part Ia) Object-orientation: Centralized vs Decentralized Control/Computation Summary

slide-6
SLIDE 6

Introduction CRC Cards

◮ Class Responsibility Collaboration ◮ Developed in the 80’s ◮ Used to

◮ Analyse a problem domain ◮ Discover object-oriented design ◮ Teach object-oriented design

◮ Object-oriented design

◮ Objects have state and behaviour ◮ ”Think objects”

slide-7
SLIDE 7

CRC Card Template

A larger example

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

slide-8
SLIDE 8

Process

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

stories

◮ Steps

  • 1. Brainstorm classes/objects/components
  • 2. Assign classes/objects/components to persons (group up to

6 peopel)

  • 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

slide-9
SLIDE 9

Library Example: Problem Description and Glossary

◮ Problem Description

◮ Library system for checking out, returning, and searching

for books. No more than 5 books can be loaned by one borrower at a time. And if a book is returned after its

  • verdue date, a fine has to be paid.
slide-10
SLIDE 10

Library Example: Problem Description and Glossary

◮ Problem Description

◮ Library system for checking out, returning, and searching

for books. No more than 5 books can be loaned by one borrower at a time. And if a book is returned after its

  • verdue date, a fine has to be paid.

Glossary

◮ Librarien

◮ The object in the system that fulfills User requests to check

  • ut, check in, and search for library materials

◮ Book

◮ The set of objects that represent Users who borrow items

from the library

◮ Borrower

◮ The set of objects that represent Users who borrow items

from the library

◮ . . .

slide-11
SLIDE 11

Library Example: Use Case Diagram

◮ Use Cases

User LibrarySystem borrow book return book search for book

slide-12
SLIDE 12

Library Example: Detailed Use Case Check Out Book

◮ Name: Check Out Book ◮ Description: The user checks out a book from the library ◮ Actor: User ◮ Main scenario:

1 A user presents a book for check-out at the check-out counter 2 The system registers the loan

◮ Alternative scenarios:

◮ The user already has 5 books borrowed

2a The system denies the loan

◮ The user has one overdue book

2b The system denies the loan

slide-13
SLIDE 13

Example II

◮ Set of initial CRC cards

◮ Librarien ◮ The object in the system that fulfills User requests to check

  • ut, check in, and search for library materials

◮ Borrower ◮ The set of objects that represent Users who borrow items

from the library

◮ Book ◮ The set of objects that represent items to be borrowed from

the library

◮ Use case Check out book main scenario

◮ ”What happens when Barbara Stewart, who has no

accrued fines and one outstanding book, not overdue, checks out a book entitled Effective C++ Strategies+?”

slide-14
SLIDE 14

Library Example: CRC cards

slide-15
SLIDE 15

Library Example: CRC cards

slide-16
SLIDE 16

Library Example: CRC cards

slide-17
SLIDE 17

Library Example: CRC cards

slide-18
SLIDE 18

Library Example: CRC cards

slide-19
SLIDE 19

Library Example: CRC cards

slide-20
SLIDE 20

Library Example: CRC cards

slide-21
SLIDE 21

Library Example: CRC cards

slide-22
SLIDE 22

Library Example: CRC cards

slide-23
SLIDE 23

Library Example: CRC cards

slide-24
SLIDE 24

Library Example: CRC cards

slide-25
SLIDE 25

Library Example: CRC cards

slide-26
SLIDE 26

Library Example: CRC cards

slide-27
SLIDE 27

Library Example: CRC cards

slide-28
SLIDE 28

Library Example: CRC cards

slide-29
SLIDE 29

Library Example: All CRC cards

slide-30
SLIDE 30

Process: Next Steps

◮ Repeat the process with other scenarios

→ completes the design

◮ Review the result

◮ Group cards ◮ Check cards ◮ Refactor

◮ Transfer the result

◮ UML class diagram ◮ UML interaction diagrams

slide-31
SLIDE 31

Example: Class Diagram (so far)

0..1 * Borrower canBorrow Book isOverdue checkOut(b:Borrower) calculateDueDate Librarien checkOutBook(b:Book) Date compare(d:Date) * * 0..1 dueDate

slide-32
SLIDE 32

Example: Sequence Diagram for Check-out book

Check Out Book Realization

slide-33
SLIDE 33

Summary

Process

◮ Further scenarios give more detail ◮ Repeat CRC process on a more detailed level

◮ e.g. to design database interaction, or user interface

◮ Choose your level of abstraction and stay there

Alternative: Build sequence and class diagrams directly (the ”modern” way)

◮ Danger: talk about the system instead of being part of the

system

◮ Possible when object-oriented principles have been

learned

◮ CRC cards help with object-oriented thinking

slide-34
SLIDE 34

Contents

From Requirements to Design CRC Cards Components (part Ia) Object-orientation: Centralized vs Decentralized Control/Computation Summary

slide-35
SLIDE 35

Software architecture

◮ Software architecture

◮ building blocks: components ◮ glue: connectors ◮ ports: interfaces to the outside

◮ Decompose the system into smaller components and their

interconnection

◮ E.g. browser, Web server, database ◮ E.g. presentation layer, application layer, domain layer

slide-36
SLIDE 36

Components

◮ Components: replacable piece of software

→ Resuable → Pluggable

◮ Well-defined interfaces: provided and required

→ ports → connectors

◮ Similar to classes: better encapsulation ◮ Component = set of collaborating classes ◮ Microservices are components

slide-37
SLIDE 37

Example Bank–ATM: UML 2.0 Component Diagram

Company Clearing− Bank ATM BC BankATM AB CB BA

Note: Cannot be expressed in Topcased and MagicDraw (cf. note on the home page)

slide-38
SLIDE 38

Example Bank–ATM: UML 2.0 Component Diagram

pinNotOK pinOk verifyPIN verifyPIN withdraw pinOk pinNotOK withdrawOK withdrawNotOk

Company Clearing− Bank ATM BC BankATM AB CB BA

slide-39
SLIDE 39

Example Bank–ATM: Configuration (composite structure diagram)

Company b:Bank c:Clearing− :CB :BC :AB :AB :BankATM :BA :BA atm0:ATM atm1:ATM

slide-40
SLIDE 40

Strong encapsulation of components

◮ Strong encapsulation

◮ What is provided to others ◮ What is needed of others

◮ Ports define a portal to a component

◮ Have interfaces: provided / required ◮ Connect to other components

slide-41
SLIDE 41

Showing interfaces

Port AB Bank Clearing Company ATM Port BC Port BA Provided Interface by port AB Required Interface by port BA Provided Interface by port BA Required Interface by port AB

slide-42
SLIDE 42

Port BA

Bank ATM <<interface>> AtmToBank pinOK pinNotOK withdrawOk withdrawNotOk <<interface>> BankToAtm verifyPIN(iban:IBAN, pin:int) withdraw(iban, amount:Money) «interface» I1 m 1 m 2 m 3 «interface» I2 m 1 m 3 C2 C1 «refine»

slide-43
SLIDE 43

Component Meta-Model

◮ Conceptual meta-model (not actual UML 2.0 meta-model)

* *

CompositeComponent

* 0..1

Component SimpleComponent Protocol Interface Port Connector

1 2

Assembly

* 0..1 1 1 * provided 1 * required *

slide-44
SLIDE 44

Component Notation

Component as a stereotype

slide-45
SLIDE 45

Realizing components

◮ No runtime representation (usually) ◮ No programming language support (usually) ◮ Different types of component concepts

◮ EJB, CORBA, COM/DCOM, .NET, JavaBeans, . . . ◮ Microservices

slide-46
SLIDE 46

Bank component with Implementation

Bank component seen from the outside Bank component seen from the inside

Bank Bank Customer Account ClearingCompanyToBank BankToAtm

*

«delegate» «delegate» * BankToATMPort «delegate» BankToClearingCompany AtmToBank «delegate»

slide-47
SLIDE 47

Detailed Class Diagram for the Bank Component

Bank name: String ... pinOK pinNotOk accountFor(a): Account ... «interface» AtmToBank pinOK pinNotOK withdrawOk withdrawNotOk Customer name address ... Account number : IBAN balance : int withdraw(amount:int): bool ... BankToATMPort verifyPIN(a,p): bool withdraw(a,m): bool pinOK pinNotOk 1 cc 1..* 1..* * c * «interface» BankToAtm verifyPIN(a,p): bool withdraw(a,m): bool * 1 b «interface» ClearingCompanyToBank verifyPIN(a,p) «interface» BankToClearingCompany pinOK pinNotOk 1 atm

◮ Rules for classes implementing components

◮ Provided interfaces must to be implemented by some class ◮ Required interfaces must to be used by one or serveral

classes

◮ No access to and from classes of other components

(exception: common datatypes)

◮ Use packages to indicate classes belonging to a

component

slide-48
SLIDE 48

Contents

From Requirements to Design CRC Cards Components (part Ia) Object-orientation: Centralized vs Decentralized Control/Computation Summary

slide-49
SLIDE 49

Marriage Agency: How to implement?

Customer sex:String birthYear:int interests:String[*] MarriageAgency matchCustomer(c):Customer[*] * public class MarriageAgency{ private List<Customer> customers = new ArrayList<Customer>(); public List<Customer> matchCustomer(c) { List<Customer> matches = new ArrayList<Customer>(); for (Customer candidate : customers) { ... // if customer matches candidate add to variable matches } return candidate; } }

slide-50
SLIDE 50

Marriage Agency: centralized control

MarriageAgency matchCustomer(c):Customer[*] match(c,p) : boolean Customer sex:String birthYear:int interests:String[*] * public class MarriageAgency{ private List<Customer> customers = new ArrayList<Customer>(); public List<Customer> matchCustomer(c) { List<Customer> matches = new ArrayList<Customer>(); for (Customer candidate : customers) { // if customer matches candidate add to variable matches if (match(c,candidate)) { matches.add(candidate); } return candidate; } } public bool match(Customer customer, Customer candidate) { .... } }

slide-51
SLIDE 51

Marriage Agency: centralized control

sd match centralized loop [for all customers p]

slide-52
SLIDE 52

Marriage Agency: decentralized/distributed control

sd match decentralized loop [for all customers]

slide-53
SLIDE 53

Marriage Agency: decentralized/distributed control

Customer sex:String birthYear:int interests:String[*] match(c:Customer) hasOppositeSex(c) hasAppropriateAgeDifference(c) hasOneInterestInCommon(c) MarriageAgency matchCustomer(c):Customer[*] *

public class MarriageAgency{ private List<Customer> customers = new ArrayList<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 candidate) { .... } }

slide-54
SLIDE 54

Design for change: centralized control

Customer sex:String birthYear:int interests:String[*] MarriageAgency matchCustomer(c):Customer[*] matchCustomerTypeA(c):boolean matchCustomerTypeB(c):boolean * CustomerTypeA CustomerTypeB

public List<Customer> matchCustomer(Customer c) { List<Customer> r = new ArrayList<Customer>(); for (Customer p : customers) { if (c instanceof CustomerA) { if (matchCustomerTypeA(p)) { r.add(p); } continue; } if (c instanceof CustomerB) { if (matchCustomerTypeB(p)) { r.add(p); } continue; } } return r; }

slide-55
SLIDE 55

Design for change: centralized control

sd match centralized loop [for all customers] alt [c instanceof CustomerTypeA]

slide-56
SLIDE 56

Design for change: decentralized control

sd match decentralized alt loop [for all customers]

slide-57
SLIDE 57

Design for change: decentralized control

Customer sex:String birthYear:int interests:String[*] match(c:Customer) MarriageAgency matchCustomer(c):Customer[*] * CustomerTypeA match(c:Customer) CustomerTypeB match(c:Customer)

public List<Customer> matchCustomer(Customer c) { List<Customer> matches = new ArrayList<Customer>(); for (Customer candidate : customers) { if (c.match(candidate)) { matches.add(p); } } return matches; }

slide-58
SLIDE 58

Centralised control

slide-59
SLIDE 59

Centralized control

Order calculate price calculate base price calculate discounts Product name price Customer name discount info OrderLine quantity * 1 1

slide-60
SLIDE 60

Distributed control

slide-61
SLIDE 61

Class diagram

slide-62
SLIDE 62

Distributed control

slide-63
SLIDE 63

Distributed Control: Class diagram

Order calculate price calculate base price calculate discounts Product name price get price for quantity Customer name discount info calculate discount OrderLine quantity calculate price * 1 1

slide-64
SLIDE 64

Centralized vs Distributed control

◮ Centralized control

◮ One method ◮ Data objects

→ procedural programming language

◮ Distributed control

◮ Objects collaborate ◮ Objects = data and behaviour

→ Object-orientation

◮ Advantage

◮ Easy to adapt

→ Design for change

◮ CRC cards lead to distributed control

slide-65
SLIDE 65

Contents

From Requirements to Design CRC Cards Components (part Ia) Object-orientation: Centralized vs Decentralized Control/Computation Summary

slide-66
SLIDE 66

Next Week:

◮ UML Class Diagrams

◮ Read/Skim the lectures notes and the UML user manual on

classes and class diagrams

◮ Send me questions and UML class diagrams for discussion

by Monday 26.2

◮ What is unclear to you? ◮ What would you like to hear more about? ◮ Why is this feature used in this digram? ◮ What does this notation in this diagram mean? ◮ . . . ◮ I am going to answer the questions and discuss your class

diagrams in the lecture → Your questions and diagrams determine the lecture