2012 quality assurance data modeling

24
/2012 254 20/09/ Quality Assurance Data Modeling SOFTENG Data Modeling Part II - Lecture 5 ealand kland | New Ze versity of Auck The Univ 1

Upload: others

Post on 18-Feb-2022

0 views

Category:

Documents


0 download

TRANSCRIPT

/2012

254

20/09/

Quality AssuranceData Modeling

SO

FTE

NG

Data ModelingPart II - Lecture 5

eala

ndkl

and

| New

Ze

vers

ity o

f Auc

kTh

e U

niv

1

Today’s Outline/2012

y 2

5420/09/

• More about Modeling

SO

FTE

NG

• Data Modeling• Creating Data Models with UMLet

eala

nd

g

klan

d | N

ew Z

eve

rsity

of A

uck

The

Uni

v

2

/2012

254

20/09/

SO

FTE

NG

More about Modeling

eala

nd

More about Modeling

klan

d | N

ew Z

e

All models are wrong;

vers

ity o

f Auc

k All models are wrong;some models are useful

(George Box)

The

Uni

v

3

Models in SE/2012 • Data models

D t t d th i l ti

254

20/09/ Data types and their relations

E.g. ER-diagrams, class diagrams

SO

FTE

NG

• Architecture models

eala

nd

Components of a system and their relations

klan

d | N

ew Z

e

• User interface models

vers

ity o

f Auc

k User interface modelsStructure of the UI(navigation, interaction, …)E.g. formcharts, screen

The

Uni

v

4

E.g. formcharts, screen diagrams

More Models in SE/2012

• State transition models

254

20/09/ System states and transitions

E.g. lexical scanners, game state machines

SO

FTE

NG

• Source code modelsSt t f d

eala

nd

Structure of program codeE.g. abstract syntax trees (AST)

klan

d | N

ew Z

e

• Call graphs

vers

ity o

f Auc

k Call graphs, dependency graphs, data flow diagrams& many more

The

Uni

v

5

& many more… …

Metamodels, Models and Model Instances

/2012

Model InstancesDistinguish between model and model instance (data)

254

20/09/ Example: the parsimonious data model (PDM)

Metamodel: describes the structure of a model

SO

FTE

NG

Metamodel describes the structure of a model

Type TypeRole Role

1owner

1owner

1partner

1partner

eala

nd Model: describes the structure of data1 *

1name String

klan

d | N

ew Z

e

CourseStudent

1..participants

name

String1upi

vers

ity o

f Auc

k

Model instance: the data itself

SE254participants

name “David”

“T ” upiname?

The

Uni

v

6

SE254 “Tom” upi

participantsname

upi ?

Domain Specific Languages (DSLs)

/2012

(DSLs)• Modeling is not necessarily done graphically;

254

20/09/

g y g p yalso textual models

• DSLs are tailored to a specific domain, i.e. they provide a model for that domain

SO

FTE

NG

provide a model for that domain• Much easier to describe a problem using a suitable

DSL than a general purpose language like Java

eala

nd

DSL than a general purpose language like Java• Example: GraphViz language for graphs

graph G {

klan

d | N

ew Z

e graph G { subgraph clusterA { a -- b; subgraph clusterC {C -- D;} } b h l { d f }

vers

ity o

f Auc

k subgraph clusterB { d -- f } d -- D e -- clusterB

The

Uni

v

7clusterC -- clusterB

}

Forward and Reverse Engineering

/2012

EngineeringForward Engineering

254

20/09/ • Generate a lower-level representation of

a system from a higher-level one• Usually: generate an implementation

Model

SO

FTE

NG

y g pfrom a model

• Examples: data model to source code,DSL to source code

Implementation

eala

nd

DSL to source code

Reverse EngineeringR hi h l l i f ti b t

klan

d | N

ew Z

e • Recover higher-level information about asystem from low-level information

• Usually: from executable implementation t d l

Model

vers

ity o

f Auc

k to model• Examples: data model from source code,

source code from a binary executable, l

Implementation

The

Uni

v

8data model from a database, documentation of legacy code

p

Re-Engineering and Round Trip Engineering

/2012

Round-Trip EngineeringRe-Engineering Model

254

20/09/

g g• Change an existing system by

first reverse engineering

Model

I l t ti

SO

FTE

NG

information about it• Use that information to do changes

d f f d i i

Implementation

eala

nd

and perform forward engineering

klan

d | N

ew Z

e

Round-Trip Engineering• Working with two different representations;

it hi b t th

vers

ity o

f Auc

k switching between them• Changes in one representation cause corresponding

changes in the other one and vice versa (both

The

Uni

v

9

changes in the other one and vice versa (both directions)

Meta-CASE Tools/2012 • Idea: a tool for creating CASE tools

254

20/09/

g• Many CASE modeling tools use 2D graph for

visualization, i.e. vertices and edgesV i h l b l ll d ti t

SO

FTE

NG

• Varying shapes, labels, allowed connections, etc.• Use commonalities for generic tool specification:

1 Specify a data model

eala

nd

1. Specify a data model2. Specify how data model elements are

represented in the 2D graph

klan

d | N

ew Z

e represented in the 2D graph• E.g. MetaEdit+, Pounamu, Eclipse GMF

String

vers

ity o

f Auc

k

Class

1 nameString

1 1

Classname

The

Uni

v

10Association

1 1

/2012

254

20/09/

SO

FTE

NG

Data Modeling

eala

ndkl

and

| New

Ze

vers

ity o

f Auc

kTh

e U

niv

11

Modeling an App with a 3 Ti r Archit ctur

/2012

3-Tier Architecture• Written docs

254

20/09/ • UI models (e.g.

screen diagrams)

SO

FTE

NG

• Written docs• Flow or sequence

eala

nd

qcharts

• State machines

klan

d | N

ew Z

e

• Written docs

vers

ity o

f Auc

k Written docs• Data models (e.g.

class diagrams)

The

Uni

v

12

Data Modeling/2012

g• Create model of the entities in a system

d th l ti b t th f i t

254

20/09/ and the relations between them from user requirements

• Often the most important artifact (for data-centric apps)

SO

FTE

NG

Analysis data model• What does the system deal with?

The concepts as they are understood by

eala

nd

The concepts as they are understood bythe expert users (“domain-specific”).-> classes, attributes, associations

• Allows you to communicate with customer & verify specification

klan

d | N

ew Z

e • Allows you to communicate with customer & verify specification• No implementation details (too early, may confuse customer)• Evolves over time (too much detail too early is a waste)

vers

ity o

f Auc

k

Design data model extends/adapts/refines analysis modelso that it becomes clear how to implement the system

The

Uni

v

13

m mp m y m

Classes/2012

254

20/09/

SO

FTE

NG

ea

land

klan

d | N

ew Z

e

• Class name and instance variables (attributes)

vers

ity o

f Auc

k

• Possibly some method signatures (operations)• Use operations as a reminder rather than a strict

l d

The

Uni

v

14implementation decision

Reusing Classes: Inheritance / Generalization

/2012

Inheritance / GeneralizationAbstract class

( l l h

254

20/09/ (superclass so general that

there are no instances)

SO

FTE

NG

ea

land “Is-a”-relation

(inheritance)

klan

d | N

ew Z

e (inheritance)

vers

ity o

f Auc

kTh

e U

niv

15

Using Inheritance in Analysis Models

/2012

Models• Single inheritance:

254

20/09/ – One general superclass, several specialized subclasses

– Substitution principle:Subclasses can be used where superclass is used

SO

FTE

NG

Subclasses can be used where superclass is used– Easier to understand than multiple inheritance

• Advantages:

eala

nd

g– Treating similar objects similarly

( “Don’t ask what kind”)R f liti f l

klan

d | N

ew Z

e – Reuse of commonalities of classes– Better maintenance

• Disadvantages:

vers

ity o

f Auc

k Disadvantages:– May be an implementation decision– May be confusing to the customer

The

Uni

v

16

Connecting the Classes: Associations

/2012

Associations1. Connect classes with a line2 Sp if m ltipli iti n h sid f ss i ti n: min m x

254

20/09/ 2. Specify multiplicities on each side of association: min..max

(min and max of connected instances on each side)3. Use roles to make the model more self-explanatory

SO

FTE

NG

p y

eala

nd

1..* 0..* 10..*partici-pant

coordi-

klan

d | N

ew Z

e

A student can A lecturer

pant nator

vers

ity o

f Auc

k A student can take an

arbitrarily number of

A course is taken by one or more st d ts (th

A lecturer teaches an arbitrary number of

A course has exactly one

di t

The

Uni

v

17

number of courses

(possibly none)

students (the participants)

number of courses

(possibly none)

coordinator

Recursive Associations/2012

• Associations that connect a class with itself;

254

20/09/ e.g. for ordering instances (e.g. hierarchies, dependencies, flow)

• Use roles to distinguish ends of associations• Example: required courses for a course

SO

FTE

NG

• Example: required courses for a course– A course may require a student to complete 0..* other

courses first

eala

nd

– Each course may be required by 0..* other courses

klan

d | N

ew Z

e

0..* requiredCourses

vers

ity o

f Auc

k

0 *

The

Uni

v

18

0..requiredByCourses

Analysis vs. Design Model/2012

y gAnalysis Model• Keep it simple (the customer

254

20/09/ Keep it simple (the customer

must understand it)e.g. only undirected associations

SO

FTE

NG

associations• Only those things that are

part of the requirements(no implementation decisions)

eala

nd

(no implementation decisions)

Design Model• Directed associations

klan

d | N

ew Z

e Directed associations(Java object references)

• Access control(interfaces public/private )

vers

ity o

f Auc

k (interfaces, public/private…)• Getters and setters• Methods for data storage,

h dli GUI

The

Uni

v

19error handling, GUI, …

/2012

254

20/09/

SO

FTE

NG

Creating Data Modelswith UMLet for Eclipse

eala

nd

with UMLet for Eclipse

klan

d | N

ew Z

eve

rsity

of A

uck

The

Uni

v

20

Creating a Diagram/2012

g gFirst install UMLet from www.umlet.com

254

20/09/

1. Select File->New->Other ->UMLet Diagram

SO

FTE

NG

2. Choose a project (“Container”)and a diagram name

eala

nd 3. Open diagram file through Package Explorer

klan

d | N

ew Z

e

4. Add diagram parts by double-clicking palette

vers

ity o

f Auc

k palette

5 E t di :

The

Uni

v

21

5. Export diagram:UMLet->Export as->PDF

Editing a Diagram/2012

g g 2

5420/09/

Drag&drop

SO

FTE

NG

Palette of available

gto move

eala

nd

elements(double-click to add)Click to

selectMove connectors

klan

d | N

ew Z

e Move connectorsto diagram element

to attach

vers

ity o

f Auc

k

Element Propertiesin UMLet markup

(edit to change text

The

Uni

v

22

(edit to change text and arrows)

Today’s Summary/2012

y y

• There are different levels of model data:

254

20/09/ metamodels, models and model instances

• Domain Specific Languages (DSLs) are languages for modeling particular domains

SO

FTE

NG

particular domains• Models are important for forward and reverse engineering, re-

engineering and round-trip engineering

eala

nd

• Meta-CASE tools support the creation of graphical modeling tools

klan

d | N

ew Z

e

• Analysis models capture requirementsso that the users can understand and verify them

vers

ity o

f Auc

k • Design models refine analysis modelsso that it becomes clear how to implement the system

• Modeling tools help to create models and code

The

Uni

v

23

Modeling tools help to create models and code

Exercise/2012

254

20/09/

Create a class diagram for the following system:A GP needs a software to manage her patients

SO

FTE

NG

A GP needs a software to manage her patients, appointments and invoices. The patients have a name, address and phone number, and the date on which th fi st isit d th GP ds t b st d t

eala

nd

they first visited the GP needs to be stored, too. Private patient’s records have also the name of their health insurance company. A patient can have several

klan

d | N

ew Z

e p y pappointments with a time and date, and several appointments can have an invoice associated with them An appointment has at most one invoice An

vers

ity o

f Auc

k them. An appointment has at most one invoice. An invoice contains several items that have a description and a price.

The

Uni

v

24