10.class and Object Diagram
10.class and Object Diagram
CLASS DIAGRAM
classes were not identified systematically. Because
we have now gone through the processes of business
requirements modeling and system requirements
modeling, we have a good source of candidate classes
in the form of system use cases.
Candidate classes are often indicated by nouns in the
use cases.
A class diagram shows us what classes exist and how they’re
related. (Officially, class diagrams can also show attributes and
operations, but that requires a lot more space.) In the case of
aggregation, composition and association, the class diagram
shows permitted run-time relationships rather than actual ones.
Relationships between classes are shown as lines with various
annotations. Even without particular knowledge of UML, its easy
to pick information out of a class diagram, just from the text.
Although the relationships on a class diagram are usually drawn
between classes, the run-time relationship is actually between
objects
Attributtes
All relationships except inheritance can indicate at either end the number
of run-time objects that are allowed to take part in the relationship (the
multiplicity of the relationship):
n: Exactly n.
m..n: Any number in the range m to n (inclusive).
p..*: Any number in the range p to infinity.
*: Shorthand for 0..*.
0..1: Optional.
For composition, the multiplicity at the composer’s end is always 1
a layer
a subsystem
a reusable library
a framework
classes that should be deployed together
Many developers will use a package diagram to show layers.
However, there are a couple problems with this approach.
Firstly, layers are chosen before any decision about how
organize source code into packages has been made (and the
organization may well be different). Secondly, a package
diagram doesn’t allow us to show some important information;
for example, the existence of the HTTPCGILayer in iCoot is
important, but it doesn’t map any package that we might
implement or borrow from a library (it’s simply an indication
that we use the HTT P protocol with the CGI extras).
Package diagrams are also not good at showing horizontal
partitions (subsystems); a deployment diagram should be used
instead.
Classes and objects are separate yet intimately related concepts.
Specifically, every object is the instance of some class, and every class
has zero or more instances. For practically all applications, classes
are static; therefore, their existence, semantics, and relationships are
fixed prior to the execution of a program. Similarly, the class of most
objects is static, meaning that once an object is created, its class is
fixed. In sharp contrast, however, objects are typically created and
destroyed at a furious rate during the lifetime of an application.
An object diagram is used to show the existence of objects and their
relationships in the logical design of a system. Stated another way, an
object diagram represents a snapshot in time of an otherwise transitory
stream of events over a certain configuration of objects. Object diagrams
are thus prototypical—each one represents the structural relationships that
may occur among a given set of class instances. In this sense, a single
object diagram represents a view of the object structure of a system. During
analysis, object diagrams are often used to indicate the semantics of
primary and secondary scenarios that provide a trace of the system’s
behavior. During design, object diagrams are often used to illustrate the
semantics of mechanisms in the logical design of a system. Regardless of
the development phase, object diagrams present concrete examples that
assist in the visualization of the associated class diagrams.
The two essential elements of object diagrams are objects and their
relationships.
Object Diagrams
Similar to class diagrams, a horizontal line partitions the text inside the
icon into two regions, one denoting the object’s name and the other
providing an optional view of the object’s attributes and their values.
Here, though, we see a tool-specific implementation that does not use a
horizontal line to completely partition the two regions.
Object diagrams are useful for illustrating a particular run-time
scenario, but they’re optional. For clarity, we would prefer to avoid
putting classes and objects on the same diagram.
objectName Object name only
:ClassName Object class only
objectName :ClassName Object name and class
For some objects, it may be useful to expose a portion or all of their attributes.
We say “some” because objects represent only a view of the object structure. The
name of each of these attributes must refer to an attribute defined in the object’s
class or any of its superclasses. The syntax includes the ability to specify a value
for each attribute We do not show class properties, such as operations, since they
are shared by all instances of the class.
Objects interact through their links to other objects which is an object diagram. A
link is an instance of an association, analogous to an object being an instance of a
class. A link may exist between two objects if and only if there is an association
between their corresponding classes. This class association may manifest itself in
any way, meaning that the class relationship could be a plain association, a
generalization, an aggregation, or a composition. The existence of an association
between two classes therefore denotes a path of communication (i.e., a link)
between instances of the classes, whereby one object may send messages to
another. All classes implicitly have an association to themselves, and hence it is
possible for an object to send a message to itself.
We’ve discussed objects and their relationships, which
constitute the essential parts of the notation for object
diagrams. However, a number of particularly knotty
development issues require slightly more than this basic
notation. As we warned in our discussion on class diagrams,
we must again emphasize that these advanced features
should be applied only as necessary to capture the intended
semantics of a scenario.
Using the same representation as for class diagrams,
additional notations that we may represent on object
diagrams include constraint, keyword label, navigation, and
link name.