You are on page 1of 13

Chapter 2

THE UML
What Is the UML?
• The UML is a visual language used to create models of programs.
• Diagrammatic representation of the programs in which one can see
the relationships between the objects in the code.
• The UML has several different diagrams — some for analysis, others
• for design, and for implementation.
Why Use the UML?
• The UML is used primarily for communication— with myself, my
Principally for team members, and with my customers.

• The UML gives a way to determine if my understanding of the system


is the same as others'(For clarity).

• UML is to recall your last several design reviews(For precision)


The Class Diagram
• It both The basic modelling describes classes and shows the
relationships between them.
The types of relationships that are possible are
• When one class is a "kind of" another class: the is-a relationship
• When there are associations between two classes
• One class "contains" another class: the has-a relationship
• One class "uses" another class
• I have three different ways of showing these. The leftmost rectangle shows just
the class' name. I would use this type of class representation when more detailed
information is not needed.
• The middle rectangle shows both the name and the methods of the class. In this
case, the Square2 has the method display. The plus sign (+) in front of display
means that this method is public— that is, objects other than objects of this class
can call it.
• The rightmost rectangle shows what I had before as well as data members of the
class. In this case, the minus sign (-) before the data member indicates that this
data member's value is private, that is it is unavailable to anything other than the
object to which it belongs.
Has-a relationship
Has-a relationship
• In Figure Car has Tires as parts. This type of has-a relationship, called
composition, is depicted by the filled in diamond. This dia - gram also
shows that a Car uses a GasStation. The uses relationship is depicted
by a dashed line with an arrow. This is also called a dependency
relationship.
• Both composition and aggregation involve one obje ct containing one
or more objects. Composition, however, implies the contained object
is a part of the containing object, whereas aggregation means the
contained objects are more like a collection of things.
• We can consider composition to be an unshared association, with the
contained object's lifetime being controlled by its containing object
Interaction Diagrams
• The UML diagrams that show how objects interact with each other are called
Interaction Diagrams.
• Sequence Diagrams are read from top to bottom.
• Each rectangle at the top represents a particular object. Although many of the
rectangles have class names in them, notice how there is a colon in front of the
class name. Some of the rectangleshave other names— for example, shapel:
Square.
•The boxes at the top give the class name (to the right of the colon) and optionally,
a name of the object (before the colon).
•The vertical lines represent the lifespan of the objects. Unfortunately, most UML
drawing programs don't support this and draw the lines from the top to the
bottom, leaving it unclear when an object actually comes into existence.
•I show objects sending messages to each other with horizontal lines between
these vertical lines.
•Sometimes returned values and/or objects are explicitly shown
and sometimes it is just understood that they are returned.
In Figure
• At the top I see that Main sends a "get shapes" message to the
ShapeDB object (which isn't named). After being asked to "get shapes,"
the ShapeDB:
- Instantiates a collection
- Instantiates a square
- Adds the square to the collection
- Instantiates a circle
- Adds the circle to the collection
- Returns the collection to the calling routine (the Main)
This diagram is called a Sequence Diagram because it depicts the
sequence of operations. Object: Class notation

You might also like