Package Diagrams
Massimo Felici
Room 1402, JCMB, KB
0131 650 5899
mfelici@inf.ed.ac.uk
Rationale
Provide a way to group Package design needs to
related UML elements balance diverse needs
and to scope their • Easier to build and test
names • Better tracking and
property transparency
Provide a way to • Working at a stable
visualize dependencies overview without the
between parts of your noise of low-level details
system • Less conflict between
• Vulnerable to changes (in distributed teams
other packages) • Easy refactoring and
Provide support for extension
analysis
Determine compilation
order
© 2004-2006 SEOC - Lecture Note 08 2
Representation of Packages
Packages contain different
elements (packages too)
A UML package establishes a
namespace
• To specify the context of a
UML, you provide the fully-
scoped name
• packageName::className
• In Java, a fully-scoped name
corresponds to specify the
Java package
It is possible to specify
visibility for owned and
imported elements
• public or private
• No elements – no
assumptions about the
package’s content
© 2004-2006 SEOC - Lecture Note 08 3
Element Visibility
Elements with public visibility are accessible
outside the package
Elements with private visibility are available
only to other elements inside the package
In Java, public and private visibilities
correspond to a class being public or private
to a Java package
If the public keyword is absent, then the
class is private to the package
© 2004-2006 SEOC - Lecture Note 08 4
Importing and Accessing Packages
<<import>>: Elements
of imported packages Target Packages
are available without
qualification in the
importing package
• public visibility
• private visibility
• Import specific elements,
rather than the whole
package
<<access>>:Accessing
packages whereas gives
private visibility to the
imported elements
© 2004-2006 SEOC - Lecture Note 08 5
Merging Packages
Creates relationships between classes of the same
name
Merge is a directed relationship
Rationale: the evolution from UML 1.x to UML 2.0 -
extending a base concept of elements without
renaming
Some Rules for package merge
• Private members are not merged
• Merging classes are generalized to corresponding merged
ones
• Maintain package scope for reference to classes
• Classes outside the intersection of packages are unchanged
• Subpackages are added, if they don’t exist
• Merge extends to subpachages with the same names
• Merge acquires imported elements
© 2004-2006 SEOC - Lecture Note 08 6
Package Dependencies
Structuring a Project with
Packages
Packages group UML
elements and organize a
logical system during design
and implementation
Manage Dependencies
• Directed dependency graphs
• Avoid cyclical package
dependencies
• Organize and allocate
project work to different
teams - Different groups
can work on different
packages without
destabilizing each other
© 2004-2006 SEOC - Lecture Note 08 7
Use Case Packages
Using packages to
organize use cases
Organize the functional
behavior of a system
Highlight which actors
interact with which
portions of the system
© 2004-2006 SEOC - Lecture Note 08 8