00a - UML.ppt

Document Sample
00a - UML.ppt Powered By Docstoc
					UML
a crash course
Alex Lo
Brian Kiefer
Overview
  Classes
  Class Relationships
  Interfaces
  Objects
  States
  Worksheet
Classes
  Drawn as a three section box:
     Name
     Fields
     Functions   Class Name
                  -Attribute1
                  +Operation1()
Classes
Fields and functions given visibility signs
 + sign indicates public
 - sign indicates private

 # sign indicates protected
Fields are shown as name:type
Functions are shown as
Function(argument1:type, …):returnType
Italic class or method names indicate the class is
abstract
Static fields and functions are underlined
Cooper Example
public abstract class Person
{
         protected String personName;
         private int age;
         public Person (String name)
         { personName = name; }
         static public String makeJob ()
         {return "hired";}
         public int getAge () {return age;}
         private void splitNames () { }
         abstract String getJob ();
}
Alternate Diagrams
Packages
  Packages are depicted as large folders
  with classes contained inside
      Package Name

       Class Name     Class Name      Class1
      -Attribute1     -Attribute1
      +Operation1()   +Operation1()
Notes
  UML does not require that you show
  everything
  To draw a note in UML


  Class Name
 -Attribute1
                 This is some sort of note
 +Operation1()
Class Relationships
   Use a solid line with a hollow arrowhead
   to show a parent class
          Class1            Class2




Class2 extends Class1
Cooper Example
public class Employee extends Person {
  public Employee (String name) {
      super (name);
  }
public String getJob () {
  return "Research Staff";
  }}
Relationships
  A single line often         Class1   Class2
  represents that one
  class contains an
  instance of another
                             Class1    Class2
  Use a diamond to show
  that one class has a
  collection of the other
  class
                            Class1     Class2
  Sometimes a small
  circle is used to show
  that the instance is
  singular
Relationship Cardinality
                     -N      -M     Class2


Exactly 1            0..1      1


                     -N      -M     Class2
Many (0 and up)
                     0..1      *


Optional (0 or 1)     -N      -M    Class2


                      0..1   0..1

One or more          -N      -M     Class2

N to M (not shown)   0..1    1..*
Relationships
  An open arrow indicates navigability – it
  shows that one class has a ref to
  another and the other may not
     Class1                                 Class2




    Class1                                    Class2
              relationship

                             relationship
Dependency
 A dashed arrow shows a dependency
 on a class that does not use an object
 ref
     Example: using static method of another
      class
      others?
           Class1              Class2
Other Relations
   Another relation can be done using the
   dashed arrows like throwing
          Class1             «bind»             Class2




 (bind can be any keyword, such as throw, send, become, friend, etc)
Interfaces
Interfaces are drawn similarly to classes,
except without a field area (usually) and
the <<interface>> stereotype
An interface which you don’t need to
define can be drawn as a “lollipop”

   «interface»
                   RemoteInterface
 InterfaceName
Interfaces
  To show a class implements an
  interface, use a dashed line with an
  open arrowhead
      Class1           «interface»
                     InterfaceName




                        Class2
   RemoteInterface
Notes on Interfaces
  While interfaces and their methods are
  always abstract in java, their methods
  do not appear italicized. As opposed to
  abstract classes and abstract methods.

*This was disagreed on between Cooper
  and our book.
Objects
  You can show an object by giving its name
  and type separated by a colon (or just
  either/or) and underlining it
  A line between objects indicates that one
  object has a reference to another.

  s:String       «uses»         :Char
Calling Methods from Objects
  You can show a
  sequence of objects
  calling methods of other        LinkedList                  List
  objects
     The order is from top to
      bottom
     The dashed line indicates
      the object over time                addFirst(:Object)
     A bold outline of the box
      represents the class is
      running on a separate
      thread
States
  UML can also be used to model the various
  states of a program or method
     Think Introduction to Logic Design
     Think events (clicks, key presses, etc.)
                click                                     complete
                                       Closed



                               click
             Opening                                           Closing
                                                click
                                       timeout
  complete
                                                                   click
                        Open           click        StayOpen
Other uses of UML
  Collaboration diagrams
  Use case diagrams
  Activity diagrams
  Deployment diagrams
  Etc.
More Resources
  Our book, p 442-447
  Safari Online:
  Java™ Design Patterns: A Tutorial
  By James W. Cooper
  Chapter 2
  UML Distilled
                     Pluggable Universal Multiple Mail Account Structure


Message Repository
                                                                LocalAccount
Contains
                                                                POP3Account
  MailAccountList

    MailAccount                               Inherits from
  (POP3, IMAP or            MailAccount                         IMAPAccount
      Local)
    MailAccount
  (POP3, IMAP or
      Local)
           ...                                                                    Use
                                   Contains

                                                                                            Internal

                                                                 LocalMailbox
                                                                                        POP3 Protocol
    MailboxList                                                 (POP3Mailbox)
                                              Inherits from
     MailBox
  (POP3/Local or              Mailbox                           IMAPMailbox             IMAP Protocol
     IMAP)
     MailBox
  (POP3/Local or
     IMAP)
           ...
                                                                                  Use
                                   Contains



                                                               LocalMailMessage
  MailMessageList                                             (POP3MaiMessage)
                                              Inherits from
   MailMessage
  (POP3/Local or            MailMessage                       IMAPMailMessage
      IMAP)
   MailMessage
  (POP3/Local or
      IMAP)
           ...
Discussion

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:12
posted:12/1/2011
language:English
pages:25