On The Stop Assignment
On The Stop Assignment
Visibility Control
Public Access
Access modifier = public
To make variables and methods visible to
all the classes outside
Has the widest possible visibility and
accessible everywhere.
In fact, this is what some times needed to
be prevented in many programs
Visible to all classes regardless of their
packages
E.g.
public int age;
public void CalAge() {}
Friendly Access
Protected Access
Access modifier = protected
Visibility level lies between public
access and friendly access
Visible to all classes and subclasses
in the same package
Visible to subclasses in other
packages
Non-subclasses in other packages
cannot access the protected
members
Private Access
Visibility Levels
Access Public
Modifier
Protected
Friendly
(Default)
Private
Protected
Private
Access
Location
Same Class
Yes
Yes
Yes
Yes
Yes
Subclasses in same
package
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
No
Subclasses in other
packages
Yes
Yes
No
Yes
No
Non-subclasses in other
packages
Yes
No
No
No
No
Rules of Thumb
1. To be visible everywhere use public
2. To be visible everywhere in the current
package and also subclasses in other
packages use protected
3. To be visible everywhere in the current
package use friendly (default)
4. To be visible only in subclasses
regardless of packages use private
protected
5. To be visible only in own class use
private
Representing objects
squares with object type, optionally
preceded by object name and colon
write object's name if it clarifies the diagram
object's "life line" represented by dashed vert.
line
Lifetime of objects
creation: arrow with 'new'
written above it
notice that an object
created after the start of the
scenario appears lower
than the others
deletion: an X at bottom of
object's lifeline
Java doesn't explicitly
delete objects; they fall out
of scope and are garbagecollected
Nesting
[balance
<>0]
alt
[balance
< 100.00]
[balance>= 100.00]
loop
[balance
< 0]
Customer Info
ref
Object
Collaboration
Business
Process
(Activity
Diagrams)
(Interaction
Diagrams)
Objects Behavior
(State Diagrams)
System Functionality
Use-case Diagrams