Data Requirements for the Amanda Model System

Download Report

Transcript Data Requirements for the Amanda Model System

ADMS-BIS
Bouwkundige Informatiesystemen
ADMS 2006
UML part 2
Jan Dijkstra - 23 oktober 2006
ADMS-BIS
Subjects
•
•
•
•
•
•
•
•
Objects & Classes
UML : Class Diagram
UML : Object Diagram
UML : Class Diagrams Exercises
Exercise Class Diagram MKW
Discussion Exercise Class Diagram MKW
UML : Class Diagrams - Advanced Concepts
Task UML-part 2
16 okt.
23 okt.
23 okt.
23 okt.
23 okt.
30 okt.
30 okt.
30 okt.
ADMS-BIS
UML Models, Views and Diagrams
• A diagram is a view into a model
– presented from the aspect of a particular stakeholder
– and provides a partial representation of the system
ADMS-BIS
UML Views
vocabulary
functionality
system assembly
configuration management
Implementation view
Design view
Use Case
view
behaviour
performance
scalability
throughput
Interaction
view
Deployment
view
logical
physical
system topology
distribution
delivery
installation
ADMS-BIS
UML Diagrams
• Structure diagram
–
–
–
–
Class diagram
Object diagram
Component diagram
Composite structure
diagram
– Deployment diagram
– Artifact diagram
• Behaviour diagram
–
–
–
–
–
Use Case diagram
Sequence diagram
Communication diagram
State diagram
Activity diagram
ADMS-BIS
Use Case diagram
ADMS-BIS
Classes/objects “course management”
Reservation
Customer
Course
ADMS-BIS
UML Class Diagrams
The class diagram provides a static structure of all the classes that exist
within the system. Classes are arranged in hierarchies sharing
common structure and behaviour and are associated with other
classes.
Class diagrams are used in:
• Analysis
To build a conceptual domain model with semantic
associations between concepts
•
•
ADMS-BIS
Class Diagram: associations between classes
Reservation
Customer
Course
ADMS-BIS
Classes and Objects
An object is described by a class.
A class may define a number of objects with identical
properties
ADMS-BIS
Object Diagram: links between objects
res22:Reservation
cust1:Customer
cname:Course
ADMS-BIS
Class diagram
A class diagram describes the type of objects in a system
and the static relationships between them.
•Static relations:
– Associations
–
Subtypes
•Static structure:
–
–
Attributes
Operations
ADMS-BIS
Class
• A class is a set of objects that
share the same properties.
Name
ADMS-BIS
Class
• A class is a set of objects that
share the same properties.
• A class has a name.
Course
ADMS-BIS
Class - attributes
• The class captures the
abstraction of properties in the
set of objects.
Name
Attributes
ADMS-BIS
Class - attributes
• An attribute of a class is
identified by name, and it
identifies a property of the
objects of the class, for which
each object takes a value.
• A class has 0 to n attributes.
Course
courseNum: Integer
title: String
datum: Date
ADMS-BIS
Class - operations
• Operations are the
processes that a class
knows to carry out.
Order
Attributes
Operations
ADMS-BIS
Class - operations
• The operations are the
‘responsibilities’ – the
things we can ask an
object to do.
• A class has 0 to n
operations.
Course
courseNum: Integer
title: String
datum: Date
addReservation()
cancel()
ADMS-BIS
UML Class Diagrams
The class diagram provides a static structure of all the
classes that exist within the system. Classes are arranged
in hierarchies sharing common structure and behaviour
and are associated with other classes.
Class diagrams are used in:
• Analysis To build a conceptual domain model with semantic
associations between concepts
• Design Structural model of a design in terms of class interfaces
• Implementation Source code documentation, exposing the
implementation
ADMS-BIS
Classes and Objects
• Objects looks like modules in some ways
Object = Identity + State + Behaviour
• Objects provide encapsulation of data
• An object is described by a class. A class may define a
number of objects with identical properties
ADMS-BIS
About an Object
• An object has a public interface defining the operations
(methods) it will support
• An object has private data called attributes, which only its
own operations can access
• An object can have private operations for its own use
• An object may know about other objects by means of
associations
ADMS-BIS
Classes - recapitulation
A class is simply represented as a box with the name
of the class inside
– The diagram may also show the attributes and operations
Rectangle
Rectangle
Rectangle
Rectangle
height
width
height
width
height: int
width: int
getArea
resize
getArea(): int
resize(int,int)
The complete signature of an operation is:
operationName(parameterName: parameterType …): returnType
ADMS-BIS
ADMS-BIS
Essentials of UML Class Diagrams
recapitulation
The main symbols shown on class diagrams are:
• Classes
– Represent the types of data themselves
• Associations
– Represent linkages between instances of classes
• Attributes
– Are simple data found in classes and their instances
• Operations
– Represent the functions performed by the classes and their
instances
• Generalizations
– Group classes into inheritance hierarchies
ADMS-BIS
ADMS-BIS
Identifying objects ?
A possible recipe
– We can identify objects in our problem context by
looking for nouns and noun phrases
– Each of these can be underlined and becomes a
candidate for an object in our solution
– Eliminate irrelevant objects
• Redundant, vague, event, outside scope, attribute, metalanguage
ADMS-BIS
The Bank Account Example
You are asked to design a system to handle current and savings accounts for a
bank. Accounts are assigned to one or more customers, who may make
deposits or withdraw money. Each type of account earns interest on the current
balance held in it. Current accounts may have negative balances (overdrafts)
and then interest is deducted. Rates of interest are different for each type of
account. On a savings account, there is a maximum amount that can be
withdrawn in one transaction.
Bank employees may check any account that is held at their branch. They are
responsible for invoking the addition of interest and for issuing statements at
the correct times.
A money transfer is a short lived record of an amount which has been debited
from one account and has to be credited to another. A customer may create
such a transfer from their account to any other. Transfers within a branch
happen immediately, while those between branches take three days.
ADMS-BIS
The Bank Account Example
You are asked to design a system to handle current and savings accounts for a bank.
Accounts are assigned to one or more customers, who may make deposits or withdraw
money. Each type of account earns interest on the current balance held in it. Current
accounts may have negative balances (overdrafts) and then interest is deducted. Rates
of interest are different for each type of account. On a savings account, there is a
maximum amount that can be withdrawn in one transaction.
Bank employees may check any account that is held at their branch. They are
responsible for invoking the addition of interest and for issuing statements at the correct
times.
A money transfer is a short lived record of an amount which has been debited from one
account and has to be credited to another. A customer may create such a transfer from
their account to any other. Transfers within a branch happen immediately, while those
between branches take three days.
Question ? Recognize the nouns!
ADMS-BIS
Nouns in the bank account example
You are asked to design a system to handle current and savings accounts for a bank.
Accounts are assigned to one or more customers, who may make deposits or withdraw
money. Each type of account earns interest on the current balance held in it. Current
accounts may have negative balances (overdrafts) and then interest is deducted. Rates
of interest are different for each type of account. On a savings account, there is a
maximum amount that can be withdrawn in one transaction.
Bank employees may check any account that is held at their branch. They are
responsible for invoking the addition of interest and for issuing statements at the correct
times.
A money transfer is a short lived record of an amount which has been debited from one
account and has to be credited to another. A customer may create such a transfer from
their account to any other. Transfers within a branch happen immediately, while those
between branches take three days.
ADMS-BIS
Nouns eliminated
Redundant - overdraft, account
Vague - amount, money
An event or an operation - transaction, deposit
Outside scope of system - bank, days
An attribute - interest, rate of interest, maximum amount, current
balance, overdraft
Meta-language - transaction, correct times, record
ADMS-BIS
Nouns left
• current account, savings account, customer,
branch, statement, transfer
Remark:
The Bank Account is derived from
Pauline Wilcox – ‘The Unified Modelling Language’ in
Msc in Systems Level Integration – Systems Partitioning
Module
ADMS-BIS
Class Diagram (without adornments)
bank account example
Customer
•
current
account,
•
savings
account,
•
customer,
•
branch,
•
statement,
•
transfer
Branch
Current Account
Savings Account
Transfer
Statement
ADMS-BIS
Association Adornments: Name, Role
• The association has a name - the descriptive term, often a
verb, for the association.
• Each association has two association ends; each end is
attached to one of the classes in the association. An end
can be explicitly named with a label. This label is called a
role name (association ends are often called roles).
employee
employer
Person
Company
works for
employee
employer
Person
Company
 has employment for
ADMS-BIS
Association: Multiplicity
Multiplicity defines the
number of objects
associated with an instance
of the association.
–
–
–
–
–
Default of 1 (1: 1)
0 or 1: 0..1
Zero or more (0..infinite): *
1 or more (1..infinite): 1..*
n..m; range from n to m
inclusive
transports
Car
Person
passenger
transports
5
Car
Person
passenger
transports
*
Car
Person
passenger
transports
1..*
Car
Person
passenger
transports
2..5
Car
Person
passenger
ADMS-BIS
Class Diagram (with multiplicities)
bank account example
1
Customer
Customer
1
Branch
0..*
Branch
0..*
1
Current
CurrentAccount
Account
1
SavingsSavings
AccountAccount
0..*
1
0..*
Transfer
1
Transfer
1
1
1
Statement
Statement
1
1
1
ADMS-BIS
Association classes
Sometimes an attribute that concerns two associated
classes cannot be placed in either of the classes
Student
*
*
CourseSection
Registration
grade
Student
*
Registration
grade
*
CourseSection
ADMS-BIS
Attribute Analysis
It is not always clear which attributes belongs to which
classes by finding out the class attributes. An attribute is
assigned to that class where it is certainly a feature.
For example:
a project leader has the attributes name, department and
age.
But what to do with the attributes project number, project duration,
starting time, and budget? These attributes clarifies something about
the relation between project leader and type of project.
This often happens if a n:m relation refers to an association between two
classes. In that case, we can define a new class, for instance project
management.
ADMS-BIS
Project
Project leader
-name
-department
-age
*
-project number
-starting time
-duration
-budget
*
Project
Project leader
-project number
-starting time
-duration
-budget
-name
-department
-age
1
1
Management
-starting time
-final time
*
*
ADMS-BIS
Generalization
A specialization / generalization
relationship, in which objects of
the specialized element (child) are
substitutable for objects of the
generalized element (parent).
• Superclass – the generalization of
another class, the child.
• Subclass – the specialization of another
class, the parent.
Customer
Corporate
Personal
Customer
Customer
ADMS-BIS
Generalization - characteristics
• Identify common features concerning behaviour
and knowledge. Define these common features
on a higher level in the inheritance hierarchy.
• The aim is at behaviour more than knowledge
when combining classes.
• Generalization is a bottum-up process.
• A superclass includes all common properties of
its subclasses.
ADMS-BIS
Specialization - characteristics
• Define a new class which is a special appearance of an
existing class.
• Specialization is a top-down process.
• A subclass can have attributes and operations that are
specific for that sub-class.
• A subclass may redefine operations of its super-class.
ADMS-BIS
ADMS-BIS
Associations vs. generalizations
Associations describe the relationships that will exist
between instances at run time
– when you show an instance diagram generated from a class
diagram, there will be an instance of both classes joined by an
association
Generalizations describe relationships between classes in
class diagrams
– they do not appear in instance diagrams at all
– an instance of any class should also be considered to be an
instance of that class’s super classes
ADMS-BIS
Aggregation
Aggregations are special associations that represent ‘partwhole’ relationships
– the ‘whole’ side is often called the assembly or the aggregate
Vehicle
Country
*
*
VehiclePart
Region
ADMS-BIS
Composition
A composition is a strong kind of aggregation
– if the aggregate is destroyed, then the parts are destroyed
as well
Building
*
Room
ADMS-BIS
Aggregation and Composition: example
A
B
Question: What is OK?
1. A
2. B
3. A & B
4. None
ADMS-BIS
Object diagram
An object diagram is shown as a class, and the name is
underscored, although an object’s name can be shown
optionally preceding the class name as:
objectname: classname.
The object does not have to be named, in which case only
the classname is shown underscored.
ADMS-BIS
Object diagram : example
Author
name: String
age: Integer
Computer
0..*
1..*
name: String
memory: String
ADMS-BIS
Object diagram : example
Author
name: String
age: Integer
Brian: Author
name = “Brain Jones”
age = 35r
Computer
0..*
1..*
name: String
memory: String
Brian’s PC: Computer
name = “Dell 486”
memory = “256MB”
Brian’sLaptop: Computer
name = “Toshiba CT”
memory = “512MB”
ADMS-BIS
References
• Sommerville, Ian (2001)
Software Engineering, 6th edition
http://www.software-engin.com
• Timothy Lethbridge & Robert Laganière (2005)
Object-Oriented Software Engineering, 2nd edition
http://www.lloseng.com
• Martin Fowler (2000, 2004)
Object-Oriented Software Engineering, 2nd edition; 3rd
edition
ADMS-BIS
NS Ticket service
Destination
• Make a class diagram of
‘NS ticket service’
including the classes
‘Ticket’ and ‘Destination’
Take ticket
ADMS-BIS
Use Case diagram ‘NS Ticket service’
Buy OV ticket
«extends»
«uses»
Buy NS ticket
Traveller
Pay ticket
ADMS-BIS
Use Case
Buy OV Ticket
Actors
Traveller
Preconditions
Traveller has a valid pass
Description
1.
2.
3.
4.
5.
6.
7.
Ticket device expects destination code
Traveller enters destination code
Extension point: NS ticket
Ticket device checks code and calculates the charge.
Shows destination code & fare. Activates ticket machine
for paying
Traveller pays (use case: Pay ticket)
Ticket device print and supplies ticket
Traveller takes ticket
Extension
Destination code = NS station.
3a. Ticket device expects ticket type
3b. Traveller enters Single/Return, Discount Y/N, Class
Exceptions
Traveller interrupt the interaction or walk away
Traveller enters an incorrect destination code
Payment is not finished off successful
Result
Traveller has ticket.
(NS can look forward to the payment)
ADMS-BIS
Make a class diagram of ‘NS ticket service’ including the
classes ‘Ticket’ and ‘Destination’
Ticket
-fromStation
-toStation
-oneWay : Boolean
-reduction : Boolean
-class
-date : Date
-price
+create()
+payPrice()
+printTicket()
Destination
*
1
-code
-name
-distance
-base price
+validateDestination()
+showPrice()
ADMS-BIS
Exercises Now
ADMS-BIS
Exercise 30 October
Ga uit van de MKW beschrijving van oefening
van UML1
• Identificeer enkele klassen
• Geef zo mogelijk relaties tussen klassen
aan