UML: The Unified Modeling Language
We can summarize those two points by saying that UML is concerned with description, and not with process.
If if you are not working in a "software production environment" and making day-to-day use of UML, it may still be very helpful to employ one or more of the above diagrams to assist your own understanding of the software you are developing and enable you to better discuss the development and any problems that arise with others. Of particular use by almost anyone working with object-oriented (or just object-based) code is the Class Diagram, so here are some further details about those:
Inheritance (or "generalization" as
you go up the hierarchy, "specialization" as you go
down)
Inheritance is an "is-a" type of relationship, or an
"is-a-kind-of" type of relationship. An alternate (and
perhaps better) conceptual model may be to think of it
as a "may-be-substituted-for" relationship (if you're
going up an inheritance hierarcy). Or, if you are going
down an inheritance hierarchy you can think of
inheritance as a "may-be-replaced-by" relationship.
Examples
Inheritance can be one of two types: Class Inheritance or Interface Inheritance. Inheritance is a parent-child relationship in which we create a new class (or interface) by using existing class (or interface) code. It is just like saying that "A is a type of B".
Examples
Many classes can inherit from a single class, but no single class can inherit from (extend) more than one class. However, interfaces are not classes, so an interface can inherit from (extend) more than one other interface.
Association (of which Composition
and Aggregation are Special Cases)
Association is the most general of class relationships
and encompasses pretty much any "logical connection" or
"working relationship" between classes. Association can
also model the idea of "containment" (the "has-a" type
of relationship), in the sense that it establishes a
"structural" relationship between two classes in which
(at a minimum) an object of one class is "connected" to
an object of another class, generallly by having a
reference to that other object as one of its member
variables. An association relationship can be
one-to-one, one-to-many, many-to-one, or many-to-many
(see the table of "multiplicities" below). In such a
relationship either one object "works for" another or
two (or more) objects work for each other, or
"cooperate". The different objects involved may or may
not exist independently of one another (that is, each
object may or may not have its own lifetime), and this
is where the distinction between a relationship that is
"just association" as opposed to the more specific
composition or aggregation comes into play.
Examples
Composition
Composition is a special kind of Association which
directly models the "has-a" relationship (sometimes
referred to as an "is-a-part-of" relationship) and
represents "strong containment" in the sense that we
have a whole/part relationship in which the whole and
its parts "come and go as one". Using composition
generally means means using instance variables in a
class that are objects of other classes. In the
composition relationship both entities are
interdependent, and sometimes one object may be thought
of as the "owner" of another.
Examples
Aggregation
Aggregation is also a special kind of Association which
also models the "has-a" relationship, but represents a
"weaker containment" than that of Composition.
Aggregation is more of a one-way association in which
the whole and its parts do not "live
and die together".
Examples
Dependency
Dependency is the relationship in which one class
object depends on another class object's specification.
This typically occurs when an object of one class
"uses" an object of another class (as a method
parameter or a local variable, for example, but not as
an instance variable), and a change in the
specification of the class being used will typically
require an update to the dependent object's class.
Examples
The different possible multiplicities (the number of things involved in a relationship) and their symbols, are summarized in the following table:
Symbol | Meaning |
---|---|
1 | Exactly 1 |
4, 7, 9 | Exactly 4, exactly 7, or exactly 9 |
0..1 | Zero or one |
3..7 | A value in the range from 3 to 7, inclusive |
* | Zero or more (an unlimited number) |
0..* | Same as above |
1..* | One or more |
Microsoft Visio is one of many tools that can be used to draw UML diagrams. Any of the diagrams mentioned above can be drawn using this tool, along with lines, arrows, multiplicities, and other features to help us understand the relationships between the entities in these diagrams. There is also a free MS Visio viewer that can be downloaded and installed from Microsoft's site. It cannot produce Visio diagrams but it can view diagrams that have been produced with the full program.