Introduction to UML - Download Now PowerPoint

Document Sample
Introduction to UML - Download Now PowerPoint Powered By Docstoc
					Coming up: Class Syntax




  Basic Class Diagrams
                                                Student
      Class Syntax
                                        major: String
                                        gpa: Real
 A box divided into compartments
                                        standing: String
   Name
   Attributes                          add(Class Section)
   Operations                          drop(Class Section)
   Responsibilities (rarely seen)
   Used-defined compartments (rarely
                                        -- The set of students
    seen)                               known to the
                                        registration system
                                        -- An exception occurs if
                                        gpa falls below 2.0
 Class Names
 The name should be a noun or noun phrase

 The name should be singular and description of each object in
  the class

 The name should be meaningful from a problem-domain
  perspective
    “Student” is better than “Student Data” or “S-record” or any other
     implementation driven name
Exercise – Class Identification

 Identify meaningful classes in the Elevator System
   http://www.web-feats.com/classes/dj/lessons/uml/elevator.htm




 Answers (possible):
       Elevator
       Elevator controller
       Door
       Button
         Elevator
         Floor
 Attributes
 Attributes represent characteristics or properties of classes

 They are place holders or slots that hold values

 The values they hold are other objects (or primitive types)
      Attribute Syntax
[visibility] name [multiplicity] [:type] [=initial-value]
   [{property-string}]
  visibility: public “+”, protected “#”, or private “-”
  name: capitalize first letter of each word that makes up the name, except for
    the first
  multiplicity: number, range, or sequence of number or ranges.
  type: built-in type or any user-defined class
  initial-value: any constant and user-defined object
  property-string: e.g, changeable, addOnly, frozen
          Attributes from an Analysis
          Perspective
 An attribute relates an object to some other object

 It has the same semantics as an association




             joe: Student
                                             Is basically the
      name: String = “Joe Jones”
                                             same as ...

                                    name
 joe: Student                                  Joe Jones : String
                                         1
  Operation Syntax

[visibility] name [(parameter-list)] [:return-
type] [{property-string}]

  visibility: “+”, “#”, “-”
  name: verb or verb phase, capitalize first letter of every word, except first
  parameter-list: coma separated list of parameters
  return-type: primitive type or user-defined type
  property-string: isQuery, sequential, guarded, concurrent
     Operation Example

     Student                           Class Section
major: String                  name: String
GPA: Real             takes>   capacity: Integer
standing: String
add(Class Section)             add(Student)
drop(Class Section)            drop(Student)
                               checkPrerequisites(Students)




        Course                         Prerequisite
      Type of Relationships in Class
      Diagrams

    A consolidated snippet of the UML Meta-model

                    Relation


Generalization    Association        Dependency



         Binary Association     N-ary Association


            Aggregation
 Associations
 An association is a structural relationship that specifies that
  objects of class may be connected to objects of another class


 Associations typically represent “long-lived” relationships
    e.g. In a library system a Person always has a name (association),
     but may infrequently have a book (dependency)
Associations
 Connect two classes

 Have an optional label

 Have multiplicities

 Are directional (related to “has a” relationship)

 Have optional roles
 Association Names
 Associations may be named (or labeled)
   The names should communicate the meaning of the links
   The names are typically verb phases
   The name should include an arrow indicating the direction in which
    the name should be read
   The direction on the name does NOT change navigability!
               Associations
                     is registered for>
 Student                                     Semester




                    teaches>        Class
 Instructor
                                   Section
  <works for




                       sponsors>
Department                                   Course
                Navigation
 The navigation of associations can be
   uni-directional
   bi-directional
   unspecified

 Navigation is specified by the arrow, not the label

                      teaches>       Class
  Instructor
                                    Section
   <works for




                        sponsors>
Department                                    Course
         Navigation

 The navigation of association without an arrowhead is assumed
  to be undefined

 Navigation has less value when modeling from a conceptual
  perspective
    Why?

 Navigation is more important during specification and
  implementation perspectives
    Why?
 Generalization
 Generalization is another kind of relationship in UML

 In a Java implementation what is this?




                                                      Graduate
  Person                   Student
                                                      Student
 Exercise – Simple Associations
 From an analysis perspective:
   Identify meaningful associations and generalization/specializations
    among classes in the Elevator System
Class Diagrams

 Class Diagrams describe
   the types of objects in a system
   their properties (attributes and operations)
   relationships between objects

 They can also include
   Grouping concepts like packages
   Constraints
   Various kinds of annotations
   Multiplicity Constraints

    A multiplicity constraint can be
       a single number
       a “*”, meaning an arbitrarily large number or simply “many”
       a range, denoted by “min..max”
       a sequence of single numbers and ranges 1..2,7,10-20




This is also called the
cardinality constraint
                   Multiplicity Constraints
                                    is registered for>
 Student                                                                Semester
                                                             1..*
                      0..*                                                  1



                                                   0..8
                                                                 1..*
                                 teaches>            Class
 Instructor
                             1..3           0..6    Section
               1..*
  <works for




               1
                             1        sponsors>           1..*
Department                                                              Course
Questions

 From the previous diagram
   How many classes can a student take?
   Do you have to be registered in any classes to be a student?
   Do I need to teach this class to be an Instructor? Do I need to
    teach ANY classes?
   Can a class have no students? Is that valid?
      Dependencies

    A consolidated snippet of the UML Meta-model

                    Relation


Generalization    Association        Dependency



         Binary Association     N-ary Association


            Aggregation
       Dependency Relationship
 It says that
  one modeling
  component
  “uses”
  another.


 If the later
  changes then,
  the former
  may have to
  change as well
 Dependencies
 Syntax:
   a dashed link
   arrowhead point to a component on which there is a dependency

 Dependencies can be defined among: classes, notes,
  packages, and other types of components

 Can dependencies go both ways?

 Any problems with having lots of dependencies?
 Aggregation
 Aggregation: is a special kind of association that means “part of”

 Aggregations should focus on single type of composition
  (physical, organization, etc.)


                Crust   1    1

                                                      1
                        1    1                  *
     Sauce Serving                     Pizza              Order
                        1..3 1             1
   Cheese Serving
                        0..9 1           4..*
   Topping Serving
                                      Slice
Composition (very similar to aggregation)

 Think of composition as a stronger form of aggregation.
  Composition means something is a part of the whole, but
  cannot survive on it’s own.




                Room                  Building
 Lets look at BookstoreExample4.jpg
 Does John McCain (who has 7 houses) have a problem using this
  system?

 If Barack Obama decides to create a Federal sales tax, how
  would we change the system?

 Why is there a display method in Item, Book, MusicCD and
  Software?

 An ItemOrder is part of how many Orders?

 Can you explain how a search works using this diagram?
Class Exercise

 Lets create the WeGrow class diagram

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:5
posted:8/31/2012
language:Unknown
pages:29