UML - TUE

Document Sample
UML - TUE Powered By Docstoc
					12
UML

•   Grafical method to develop models
•   Industry standard
•   Different diagrams for different aspects
•   Static diagrams:
    –   Classes
    –   Use case
    –   Deployment
•   Dynamic diagrams
    –   Sequence
    –   State machine
•   Running example: Observer Pattern (A = abstract, C = concrete)
 12
 Class diagrams
A class is represented by a box




                                                    Association
                                                                              AObserver
       ASubject                        Class name
                                   1                                   *
     observers: array(AObserver)

                                       Attributes                 observers



      attach(AObserver)                Methods                                $update()
      detach(Aobserver)
      notify()




                 forall obs in observers obs.update()
12 ASubject                                 AObserver


                               observers

attach(AObserver)
detach(Aobserver)                          $update()
notify()


                Inheritance                                      versus
                     1                *
  CSubject                                    CObserver
                     subject
 state: State
                                             state:State
                                                           Mutual dependency!
 getState(): State                          update()
 setState(State)
12
 CSubject           Composition
                       Static ownership relation
                       Owner creates object at its own creation
                       Object disappears when owner disappears

getState(): State
setState(State)      Aggregation
                         Dynamic ownership relation
                         Owner creates/destroys object at any time

                    Association
State                    Reference to an object owned by yet another object



                     Dependency
                         component depends on component to which
                         arrow points
12                                                <<interface>>       Stereotype
                                                  Player



                                                  methods


       Package
                                                             Interface inheritance
                                                             (realization)
                                                   RealPlayer



                                                   methods


Do not include too many classes in one diagram (readability) – tools support that
classes appear in different diagrams
12
Sequence diagrams

• Model dynamic behavior
• Used to describe some sequence of method calls for important
  sequences (typical or complicated)
• More general dynamic behavior is captured by state diagrams
• Control of a single thread jumps from object to object when
  calls/returns are made
    12
(Outside)
 Actor
                                   :CSubject                           :CObserver
                                                     attach(this)



             setState(state)
                                                     notify()

                                                      getState()

                                                       state




    Notice that contol “jumps”: actor can be considered as a separate thread
12
                 Object creation



                 Call: object becomes active




                  Return: object becomes inactive


     destroy()
12
          System name

              UC1

                     generalization

              UC1’
actor


              UC2

                     Extend/include

               UC3




        Use Case
12
State machines

• General dynamic behavior of classes
• In contrast to use cases that are for a typical scenario only, state
  machines describe behavior for all uses
• State machines can send messages to other state machines and
  cause a transition there
• With a state transition, there can be a trigger and an action
• If there is no trigger, the transition is always made
    12
CObserver
                              /subject.attach(this)                   …/subject.detach(this)
       (Initial transition)


    free                                  attached                detached




                                                      update()/
                                     attach(this)/
                                                                         updating


                                waiting
                                                                                     /state=subject.getState()


                                                                             updated

                                                                             usually some
                                                                             operations on state
12                                                        setState(state)


                                        consistent                          updated


                                                                                        /notify();n=0
                                         n=|observers|/
    /observers =Ø
                                                                            notifying
                attach(obs)/observers +=obs

 waiting
                                                getState()/n+=1      |observers| !=0/observers(n).update()


                                                                            updateObserver
detach(obs)/observers -=obs

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