Title: Packages EEE321'04
1PackagesEEE321.04
Royal Military College of Canada Electrical and
Computer Engineering
Refs Booch Ch 12
- Maj JW Paul
- Jeff.Paul_at_rmc.ca
- 1-613-541-6000 x6656
Based on a series of Lectures by Dr Scott Knight
2There are 10 kinds of people in the world.Those
who understand binary,
and those who dont...
3Review Singleton Pattern
- Print Spooler
- Network Services object
- File System
4Review
From http//bdn.borland.com/article/0,1410,31863,
00.htmlclassdiagrams
5Review
From http//bdn.borland.com/article/0,1410,31863,
00.htmlclassdiagrams
Multiplicities Meaning 0..1 zero or one
instance. 0.. or no limit (including
none). 1 exactly one instance 1.. at least one
instance
Are there any object here?
6A Class diagram gives an overview of a system by
showing its classes and the relationships among
them. Class diagrams are static -- they display
what interacts but not what happens when they do
interact. The class diagram below models a
customer order from a retail catalog. The central
class is the Order. Associated with it are the
Customer making the purchase and the Payment. A
Payment is one of three kinds Cash, Check, or
Credit. The order contains OrderDetails (line
items), each with its associated Item. UML class
notation is a rectangle divided into three parts
class name, attributes, and operations. Names of
abstract classes, such as Payment, are in
italics. Relationships between classes are the
connecting links. Our class diagram has three
kinds of relationships. association -- a
relationship between instances of the two
classes. There is an association between two
classes if an instance of one class must know
about the other in order to perform its work. In
a diagram, an association is a link connecting
two classes. aggregation -- an association in
which one class belongs to a collection. An
aggregation has a diamond end pointing to the
part containing the whole. In our diagram, Order
has a collection of OrderDetails. generalization
-- an inheritance link indicating one class is a
superclass of the other. A generalization has a
triangle pointing to the superclass. Payment is a
superclass of Cash, Check, and Credit. An
association has two ends. An end may have a role
name to clarify the nature of the association.
For example, an OrderDetail is a line item of
each Order. A navigability arrow on an
association shows which direction the association
can be traversed or queried. An OrderDetail can
be queried about its Item, but not the other way
around. The arrow also lets you know who "owns"
the association's implementation in this case,
OrderDetail has an Item. Associations with no
navigability arrows are bi-directional. The
multiplicity of an association end is the number
of possible instances of the class associated
with a single instance of the other end.
Multiplicities are single numbers or ranges of
numbers. In our example, there can be only one
Customer for each Order, but a Customer can have
any number of Orders. This table gives the most
common multiplicities. Multiplicities Meaning 0..
1 zero or one instance. The notation n . . m
indicates n to m instances. 0.. or no limit
on the number of instances (including
none). 1 exactly one instance 1.. at least one
instance Every class diagram has classes,
associations, and multiplicities. Navigability
and roles are optional items placed in a diagram
to provide clarity.
7Object Characteristics
Collaboration Diagram
8State
- where in memory do objects go
- different constructor invocations
- destructor invocations
9Memory storage types
- Static Memory
- global variables
- static class members
- static function variables
- Automatic Memory (Stack)
- local variables
- function parameters
- Free Store (Heap)
- memory explicitly requested by programmer
10Memory Storage
Address FFFF
Address 0000
Static
Stack
Free Memory
Heap
Fixed size doesnt grow
Grows into higher memory
Grows into lower memory
11class ExampleClass int i //prim. type
variable stored with the //ExampleClass object
in heap AnotherClass handleName //handle
stored with ExampleClass object //note no
object exists AnotherClass yet static int
j //primitive type var. in static
memory //note one copy used for the whole
class static AnotherClass anotherName //handle
is stored in static mem //note no object
exists yet static anotherName new
AnotherClass() //new object is stored on the
heap //all instances use this single object
public ExampleClass handleName new
AnotherClass() //new object is stored on the
heap //each instance creates its own object
public someFunction() int i //prim.
type variable stored on the stack AnotherClass
someName new AnotherClass() //where??
12Todays Class - UML Packages
- A mechanism for grouping things
- In this course packages will mainly be groupings
of classes - Packages can be nested
13Packages - higher level views
UML class diagram
14Detail of Packet Controller Logic
TempRamp
ProcessController
getTemp()
1
1
-currentRamp
heaterList
0..
0..
Clock
TempController
(from Utilities)
setJob()
-systemClock
getTime()
1
1
Heater
1
1
(from Drivers)
-controlledHeater
setTemp()
15Detail of Packet Drivers
16Detail of Packet Utilities
Clock
(from Utilities)
getTime()
17Java Packages
- Each class is a member of a package
- An object can use the class specifications for
other classes in the package of its class - To use the specification of classes which are not
in its package an object must import the class
18Packages - a soln to the complexity
- Apply the concepts of abstraction and
decomposition to the hierarchy - Coupling and Cohesion (inside view)
- Abstraction (outside view)
19Information Hiding in Packages
- Should other packages have complete access to the
inside of other packages?
20Information Hiding
assuming the class is public
21Rational Rose
22Using Java Packages
- Explicit names
- The package keyword
- The import keyword
- importing a class
- importing a package
- The unnamed package java.lang is always imported
23Packages in Java
package myPackage import java.net. import
java.io.File public class myClass public
firstMethod() File f new File() secondMet
hod() Vector v new java.util.Vector() p
rivate thirdMethod()
implicit
explicit
24Java Packages and Directories
- Strong relationship between packages and
directories in the Java environment - The concept of CLASSPATH
- resolving a package name
javac classpath c\mycode c\mycode\myPackage\sub
Package\myClass.java java classpath c\mycode
myPackage.subPackage.myClass
25Package Example
From http//www.vinci.org/uml/packagex.html