A Quick UML Introduction

Download Report

Transcript A Quick UML Introduction

A Quick UML Introduction
2/9/98
Thomas O’Reilly
1
What is UML and why use
it?


Unified Modeling Language
UML is a way of visualising models



UML is an industry standard
UML is already used by many people in LHCb


It may become standard for LHCb
UML is the default method in Rational Rose

2/9/98
We are interested in class diagrams. Class diagrams
work with classes and the relationships between them
Rational Rose can turn UML diagrams into C++ code
Thomas O’Reilly
2
Classes
Name of the class
Attributes of the class
(data members)
Operations of the class
(member functions)
2/9/98
Thomas O’Reilly
3
Inheritance
The arrow symbol is used to
show derived types
Dog and Cat are both
subclasses of Mammal



They inherit from the class
Mammal
Key phrase
“A dog ‘is a kind of’ Mammal”
The code equivalent is


class Dog : public Mammal{
...
}
2/9/98
Thomas O’Reilly
4
Aggregation

This black diamond symbol is
used to show that an object of
type Car will contain an object of
type Engine

code equivalent
class car{
private:
Engine engine


Key phrase “car ‘has an’ engine”
The name of the object contained
is the name on the arrow (engine)





2/9/98
The negative sign before engine
means private containment
+ public
# protected
- private
The numbers show cardinality
Thomas O’Reilly
5
More Aggregation


The empty diamond
means that a reference to
the object will be
contained
An object of type Person
will contain the address of
objects of type Cat and
Dog (or NULL pointers)
code equivalent
class person{
private:
Cat *MyCat
Dog *MyDog


2/9/98
Thomas O’Reilly
Numbers show cardinality
6
Cardinality




The numbers on the ends
of relationship arrows
show cardinality
Cardinality is the number of
objects of that type that
your object will be
associated with
A person may have no dog
or one dog only. A dog
however has to have
exactly one owner
A person may own as many
fish as he likes

2/9/98
Thomas O’Reilly
The fish will be held in a
container ( for LHCb : STL
vector<Goldfish*> )
7
Dependency
(Use Relationship)



2/9/98
Thomas O’Reilly
Drawn as a dotted
arrow
Used when one class
may require the
services of another
In this example the
Printer knows about
the class Formatter
so that it can use its
services
8