Uml

102
Amirkabir University of Technology Amirkabir University of Technology Department of Computer engineering & IT Department of Computer engineering & IT Software Engineering II Software Engineering II Unified modeling Language Unified modeling Language (UML) (UML) April 2006 In the Name of GOD

description

uml

Transcript of Uml

  • Amirkabir University of TechnologyDepartment of Computer engineering & IT

    Software Engineering II

    Unified modeling Language (UML)

    April 2006

    In the Name of GOD

    *Unified Modeling Language

    Table of ContentsReferencesOO ParadigmModelingOverview of UML

    *Unified Modeling Language

    References1- The Unified Modeling Language User Guide, Grady Booch, James Rumbaugh, Ivar Jacobson 2- The Unified Modeling Language Reference Guide, Grady Booch, James Rumbaugh, Ivar Jacobson 3- Mastering UML with Rational Rose 2002, Wendey Rogss, 2002, Cybex

    *Unified Modeling Language

    OO Paradigm . :Encapsulation: . :

    *Unified Modeling Language

    OO ParadigmInheritance: . .

    Polymorphism: .

    *Unified Modeling Language

    ModelingModel:: : Why Modeling:Big Problem n Smaller Problem: 1- / 2- 3- ( )4-

    *Unified Modeling Language

    Modeling

    :

    1- .2- .3- : 4-

    *Unified Modeling Language

    Modeling UML:1- Use Case View: - Requirements and Features - Analyst2- Design View: - Problem and Solution - Designer and Programmer3- Process View: - Multithreading - Programmer4- Implementation View: - Technologies - Programmer5- Deployment View: - Hardware and Topology - Designer and Technologist

    : view .

    *Unified Modeling Language

    Modeling

    *Unified Modeling Language

    Modeling Rational Rose:1- Use Case View: Use Case View in UML Standard2- Logic View: Design View and Process View in UML Standard3- Component View: Implementation View in UML Standard4- Deployment View: Deployment View in UML Standard

    *Unified Modeling Language

    Overview of UML UML :1- Basic Building Blocks: The Vocabulary of the UML

    2- Rules: Specify the Well-formed Model: Semantically Self-consistent and in harmony with all its related models.

    3- Common Mechanisms: An UML model is made simpler by presence of common mechanisms

    *Unified Modeling Language

    Basic Building Blocks1- Things Structural Things: - Class - Interface - Collaboration - Use Case - Active Class - Component - Node Behavioral Things: - Message - State Grouping Things: - Package Annotational Things: - Note

    *Unified Modeling Language

    Basic Building Blocks2- Relationships

    Dependency

    Association

    Generalization (is-a)

    Realization

    *Unified Modeling Language

    Basic Building Blocks3- Diagrams1- Class Diagram2- Object Diagram3- Use case Diagram4- Sequence Diagram5- Collaboration Diagram6- Statechart Diagram7- Activity Diagram8- Component Diagram9- Deployment Diagram

    *Unified Modeling Language

    Basic Building Blocks - structural things1- Class: .

    : .

    *Unified Modeling Language

    Basic Building Blocks - structural things2- Interface: External Behavior Visible (Specification)

    : Public . Interface .

    *Unified Modeling Language

    Basic Building Blocks - structural things3- Use Case: Actor

    : - Class Use Case . Use Case .- Actor: Active . ( )

    *Unified Modeling Language

    Basic Building Blocks - structural things4- Collaboration: .

    : - Use Case Collaboration .- Use Case Collaboration ( = 1 n )- 1 Use Case --- 0 n Collaboration- 1 Collaboration --- 1 n Class1 Class --- 1 n Collaboration- Rational Rose Use Case Realization .

    *Unified Modeling Language

    Basic Building Blocks - structural things5- Active Class: .

    : - Active Class .

    *Unified Modeling Language

    Basic Building Blocks - structural things6- Component: Interface .

    *Unified Modeling Language

    Basic Building Blocks - structural things7- Node: .

    *Unified Modeling Language

    Basic Building Blocks Behavioral thing1- Message : Operation

    *Unified Modeling Language

    Basic Building Blocks Behavioral thing2- State Machine: . :1- State 2- Event 3- Response 4-

    *Unified Modeling Language

    Basic Building Blocks Grouping Thing1- Package: .Package .

    *Unified Modeling Language

    Basic Building Blocks Annotational Thing1- Note:

    Rational Rose Document Window Attach File .

    *Unified Modeling Language

    Relationships1- Association: a relationship between classes indicates some meaningful and interesting connectiona structural relationship that describes a set of links, a link being a connection between objects.

    *Unified Modeling Language

    Relationships1- AssociationAssociation Notation:

    *Unified Modeling Language

    Relationships1- AssociationMultiplicity: Multiplicity A defines how many instances of type A can be associated with one instance of type B at some point Mother Child11..*Actor Film**performs-inGame Player12..6 Multiplicity :

    Exactly one - 1Zero or one - 0..1Many - 0..* or *One or more - 1..*Exact Number - e.g. 3..4 or 6Or a complex relationship e.g. 0..1, 3..4, 6..* would mean any number of objects other than 2 or 5

    *Unified Modeling Language

    Relationships1- AssociationMultiplicity:

    *Unified Modeling Language

    Relationships1- AssociationAggregation: A Special Kind of Association:- Aggregation: whole/part relationships, Instances on one side are aggregates (or wholes) and the instances on the other side are their parts.- An association that models HAS-A relationships- The objects can exist independently or each other- No one object is more important than the other- An Aggregation relationship may be called isPartOf or consistsOF.

    SchoolStudent0..*1

    *Unified Modeling Language

    Relationships1- AssociationComposition: A Special Kind of Association:- Composition: Strangle relationship, If the parts in the part-whole relationship are non-shareable.- One can not exist without the other- Composition is a anti-symmetric and transitive relation.- In aggregation relationship, the part may be included in several aggregates and its owner may also change over time.

    SchoolDepartment11..*

    *Unified Modeling Language

    Relationships1- AssociationExamples for aggregation and composition relationships:

    *Unified Modeling Language

    Relationships2- Dependency: . B A .

    - occurs when one object depends on another- if you change one object's interface, you need to change the dependent objectDirected is optional and label is optional.

    *Unified Modeling Language

    Relationships3- Generalization: is-a. .- Objects of the Specialized element (the child) are substitutable for objects of the generalized element (the parent).- The child shares the structure and the behavior of the parent. Child class is a special case of the parent class

    *Unified Modeling Language

    Relationships4- Realization: . . .a semantic relationship between two elements, wherein one element guarantees to carry out what is expected by the other element.Where? Between interfaces and classes that realize them Between use cases and the collaborations that realize them...

    *Unified Modeling Language

    Diagrams :Use Case : .

    : . .1- Actor: . .2- Use Case: Actor Actor .

    - What not How- Use Case .- Use Case View .- .

    *Unified Modeling Language

    Diagrams :Use Case : :- Actor - Use Case - Actor Use Case :1- Actor : : : Admin ...2- Actor :- (Packaging)- Generalization - Stereotype

    *Unified Modeling Language

    Diagrams :Use Case :3- Actor : --- > Use Case

    *Unified Modeling Language

    Diagrams :Use Case :4- Use Case :- Package- Stereotype - Generalization

    *Unified Modeling Language

    Diagrams :Use Case :5- Actor Use case : Association

    Association : - Actor . - Actor .

    *Unified Modeling Language

    Diagrams :Use Case :6- Use case Dependency Dependency . .

    Stereotype :1- : B A .2- : B ( ...) A .

    *Unified Modeling Language

    Diagrams :Use Case :

    *Unified Modeling Language

    Diagrams :Activity Diagram : An Activity diagram shows the flow from activity to activity.An Activity is an ongoing nonatomic execution with in state machine.Activity result in some actions

    .- .- - ()- ( )

    - .- .

    - Activity Diagram Statechart State Machine .- Activity Diagram: Activity Centric Statechart: State Centric

    - Statechart Object .

    *Unified Modeling Language

    Diagrams : Activity Diagram Elements:1- Activity State: .

    2- Action State: . Method Call Pure Computation

    Rational Rose State Action . RR Activity State Activity .Activity: represents the performance of task or duty in a workflow.State: represents a condition or situation during the life of an object during which it satisfies some condition or waits for some event.

    *Unified Modeling Language

    Diagrams : Activity Diagram Elements: RR Activity State Action .on entry: the task must be performed when the object enters the state or activityonexit: the task must be performed when the object exits the state or activitydo: the task must be performed while in the state or activity until existingon event: the task triggers an action only if a specific event is received.

    3- Start/End State:- - 0 n

    *Unified Modeling Language

    Diagrams : Activity Diagram Elements:4- Transition: . :- Trigger less: () . Activity Activity- Guarded: . State

    4- Branch Decision: Transition (Guard Conditions) . Transition Decision.

    *Unified Modeling Language

    Diagrams : Activity Diagram Elements:4- Fork & Join (Synchronization): Fork: . ( ) Join: . ( )

    RR Synchronization . .

    - Swimlane .- Fork Join .- Activity Co-Routine . Object Flow .

    *Unified Modeling Language

    Diagrams : Activity Diagram Elements:5- Swimlane:: .- Business .

    - Swimlane Actor Object ... .- Statechart .- Swimlane . ( )

    *Unified Modeling Language

    Diagrams : Activity Diagram Activity Diagram Use Case Sample :

    *Unified Modeling Language

    Diagrams : Class DiagramDefinition: A class diagram is a diagram that shows a set of classes, and collaborations and their relationships

    - Class diagrams contain classes and object diagrams contain objects- Class diagrams are more prevalent than object diagrams. Normally you will build class diagrams plus occasional object diagrams illustrating complicated data structures

    - Logical view . Structural Modeling Static .- RR Package .

    Use Class Diagrams To:Analysis: Show common roles and responsibilities of the entities that provide the system's behavior.

    Design: Capture the structure of the classes that form the system's architecture.

    *Unified Modeling Language

    Diagrams : Class Diagram- Package . :

    - Class Diagram :1- Class 2- Interface 3- Collaboration 4- Dependency, Generalization and Association- () :1- Interaction Diagram (Sequence or Collaboration Diagram)2- Statechart Diagram 3- Activity Diagram

    *Unified Modeling Language

    Diagrams : Class Diagram- : - : User Data Type Enumeration ... Stereotype .

    *Unified Modeling Language

    Diagrams : Class DiagramVisibility: Specify whether attribute or Operation cab be used by another classes.

    1- Public: members of a class are accessible to all clients. This is the default access.

    2- Protected: members of a class are accessible only to subclasses, friends, or to the class itself.

    3- Private: members of a class are accessible only to the class itself or to its friends.

    4- Friend (Implemented in RR): the class is accessible only by the implementation of the package containing the class.

    *Unified Modeling Language

    Diagrams : Class DiagramMultiplicity: .

    - Syntax: min .. max- Cases: 0 .. 1 1 .. 1 example: main form Abstract (No Instance) . 0 .. 0 Operation Class Scope ( ) Utility Class .Dim m as math s = m.sin(90)

    0 .. N 1 .. N N .

    Attributes:- Syntax: [visibility] name [multiplicity] [:type] [= initial value] [{property}]

    - Visibility .- Multiplicity RR .- Property Changable Frozen Addonly .

    *Unified Modeling Language

    Diagrams : Class DiagramProperty Cases:- .- Changeable (default): Read / Write- Frozen: Write Once .: Const Auto number- AddOnly: Multiplicity > 1 . . :

    Operations:- Syntax: [visibility] name [(in|out|inout) parameter name: type = default value, . . .)] [: return type] [{property}]Example: ConvertToGerog (PerDate: String = CurDate): Date- Visibility .

    *Unified Modeling Language

    Diagrams : Class DiagramGeneralization Relationship: A generalization is a relationship between a general thing (called the superclass or parent) and a more specific kind of that thing (called the subclass or child)

    Stereotypes:1- implementation: child inherits the implementation of the parent but does not make public nor support its interfacesConstraints:1- Complete: all children in the generalization have been specified in the model2- incomplete: all children in the generalization havent been specified in the model

    *Unified Modeling Language

    Diagrams : Class DiagramAssociation Relationship: A association is a structural relationship, specifying that objects of one thing are connected to objects of another.

    - Navigation:Possibility to navigate from objects of one kind to objects of other kind.

    - Visibility: indicated in role name. 1- Public: objects at the end are accessible to any objects outside the association 2- Private: objects at the end are not accessible to any objects outside the association 3- Protected: objects at the end are not accessible to any objects outside the association, except for children of the other end

    *Unified Modeling Language

    Diagrams : Class DiagramAssociation Relationship:- Qualification:By given an object of workDesk an given a particular value of JobID, can navigate to zero or one object of ReturnedItem.

    - Composition and Aggregation:

    SchoolStudent0..*1SchoolDepartment11..*

    *Unified Modeling Language

    Diagrams : Class DiagramRealization Relationship: A realization is a semantic relationship between classifiers in which one classifier specifies a contract that another classifier guarantees to carry out.

    *Unified Modeling Language

    Diagrams : Class DiagramExample:

    *Unified Modeling Language

    Diagrams :Object Diagram : An Instance is a concrete manifestation of an abstraction to which a set of operation can be applied and which has a state stores the effects of operations.

    An Object is a instance of a class: concrete manifestation of a class

    - An object is something that takes up space in the real or conceptual world

    Instance .- Usecase - Node - Association - Component

    - When you model instances, youll place them in 1- Object Diagram (visualize their structural details) 2- Interaction and activity diagrams (visualize their participation in dynamic situations) 3- Class diagram (show the relationship of an object to its abstraction)

    - The classifier of an instance is usually static

    *Unified Modeling Language

    Diagrams :Object Diagram Object Name: every instance must have a name that distinguish it from other instances within its context.

    Object Operation: is declared in objects abstractionSyntax: className.OperationName() ex.: trans.Commit()

    *Unified Modeling Language

    Diagrams :Object Diagram Object State: is all the properties of the object (usually static) + the current values of each these properties (usually dynamic)

    *Unified Modeling Language

    Diagrams :Object Diagram : An object diagram is a diagram that shows a set of objects and their relationships at a point in time (for model object structures)

    - An object diagram shows the existence of objects and their relationships in the logical design of a system- An object diagram is essentially an instance of a class diagram or static part of an interaction diagram

    To model an object structure:1- Identify the mechanism: A mechanism represents some function or behavior of the part of the system that results from the interaction of a society of classes, interfaces 2- For each mechanism, identify the classes, interfaces, and their relationships.3- Use scenario to walk through these things. Freeze that scenario at a moment in time and render each object that participates in the mechanism.4- Expose the state and attribute value of each object. 5- Expose the links among these objects (instances of associations)

    *Unified Modeling Language

    Diagrams :Object Diagram Object Diagram Example1:

    RR Object Diagram . Collaboration Diagram Message Note .

    *Unified Modeling Language

    Diagrams :Object Diagram Object Diagram Example2:

    *Unified Modeling Language

    Diagrams :Interaction Diagram : An Interaction is a behavior that comprise a set of messages exchanged among a set of objects within a context to accomplish a purpose.

    A Message is a specification of a communication between objects that conveys information with the expectation that activity will ensue.

    -Interaction Diagrams: 1- Sequence diagram 2- Collaboration diagram ( )

    - Context: 1- Collaboration 2- Operation 3- Class

    - Objects and Roles: 1- Concrete object 2- Prototypical object: object Abstract Object .

    *Unified Modeling Language

    Diagrams : Interaction Diagram -Link:A Link is a semantic connection among object.an instance of an association or one object send a message to the another.Visibility Stereotypes:1- Association: object is visible by association2- Self: object is visible because it is the dispatcher of the operation.3- Global: object is visible because it is in an enclosing scope.4- Local: object is visible because it is a local scope.5- Parameter: object is visible because it is a parameter.

    -Message:A Message is a specification of a communication between objects that conveys information with the expectation that activity will ensue.Message -> Action -> Change StateKinds of Actions:1- Call: invokes an operation on an object2- Return: returns a value to the caller3- Send: send a signal to an object (Asynchronous call)4- Create: creates an object5- Destroy: destroys an object

    *Unified Modeling Language

    Diagrams : Interaction Diagram -Message Sequencing:Can explicitly model the order of the messages by prefixing each messages with a sequence number set apart by a colon separator.

    -Flow of Control:1- Nested or Procedural 2- Flat

    *Unified Modeling Language

    Diagrams : Interaction Diagram

    - Object Lifetime:To specify if an object or link enters and/or leaves during an interactionConstraints:1- New: instance is created during execution of enclosing interaction2- Destroyed: instance is destroyed prior to completion of execution of enclosing interaction3- Transient: is created during execution of enclosing interaction but is destroyed before completion of execution

    Modeling Flow of Control:The most common purpose of interaction diagrams is modeling the flow of control that characterizes the behavior of system, class or an individual operation.To model a flow of control:1- set the context for the interaction2- identifying which objects play a role. determine their initial attributes values, states and roles.3- identifying the links and messages that connect them. Identifying stereotyps, constraints, parameters and return values4-convey the necessary detail of the interaction.

    *Unified Modeling Language

    Diagrams : Interaction Diagram Kinds of Modeling Flow of Control:1- by time: emphasize the time order of messages sequence diagram2- by organization: emphasize the structural organization of the objects collaboration diagram

    *Unified Modeling Language

    Diagrams :Interaction Diagram : An Interaction diagram shows an interaction, consisting of a set of objects and their relationships, including the messages that may be dispatched among them.

    -Interaction Diagrams: 1- Sequence diagram 2- Collaboration diagram ( )

    - Contents: 1- Objects 2- Links 3- Messages

    *Unified Modeling Language

    Diagrams :Interaction Diagram : A Sequence diagram is an interaction diagram that emphasize the time ordering of messages

    Appropriate features:1- object lifetime: represents the existence of object over a period of time2- focus of control: shows the period of time during which an object is performing an action

    X: ObjectsY: Time

    *Unified Modeling Language

    Diagrams :Interaction Diagram : An Collaboration diagram is an interaction diagram that emphasize the structural organization of the objects.

    Appropriate features:1- sequence number: to indicate the time order of a message2- path and path streotype

    More complex flows:1- iteration: by prefixing the sequencenumber with expressionsuch as [i:=1..n]2- branch: by prefixing the sequence number with condition clause such as [x>0]

    *Unified Modeling Language

    Diagrams :Interaction Diagram Modeling Techniques: 1- Modeling Flow of Control by Time Ordering

    *Unified Modeling Language

    Diagrams :Interaction Diagram Modeling Techniques: 1- Modeling Flow of Control Organization

    *Unified Modeling Language

    Diagrams :Statechart Diagram State machine::

    A state machine is a behavior that specifies the sequence of states an object goes through during its lifetime in response to events, together with its responses to those events.

    A state is a condition or situation during the life of an object during which it satisfies some condition, performs some activity or waits for some event.

    An event is the specification of a significant occurrence that has a location in time and space. (trigger a state transition)

    A transition is a relationship between two sates indicating that an object in the will perform certain actions and enter the second state when a specified event occurs and specified condition are satisfied.

    An activity is ongoing nonatomic execution within a state machine.

    An action is an executable atomic computation that results in a change in state of the model or the return of a value.

    - state machine () interaction Object .

    *Unified Modeling Language

    Diagrams :Statechart Diagram

    - state machine Object instance . State machine can be visualized in two ways:1- Activity diagram: focus on the activities that take place within the object.2- Statechart diagram: focus on the event-ordered behavior of an object.

    *Unified Modeling Language

    Diagrams :Statechart Diagram

    A state is a condition or situation during the life of an object during which it satisfies some condition, performs some activity or waits for some event.

    A state is a several parts:1-name2-entry/exit action3-internal transition: are handled without causing a change in state4-substates: nested structure of a state involving 1-disjoint (sequentially active) or 2-concurrent substates5-deffered events: a list of events that are not handled in that state but, rather, are postponed and queued for handling by the object in another state.

    *Unified Modeling Language

    Diagrams :Statechart Diagram

    A transition is a relationship between two sates indicating that an object in the will perform certain actions and enter the second state when a specified event occurs and specified condition are satisfied.

    - transition . state . (join & fork)

    A transition has five parts:1-source state2-event trigger3-guard condition4-action5-target state

    - event guard condition event .

    *Unified Modeling Language

    Diagrams :Statechart Diagram substates:A state that has substates that is, nested states is called composite state.A composite state may contain either concurrent or sequential substates.

    1-sequential substates:After dispatching entry action (if any), control passes to the nested state and dispatching its entry action (if any) and reverse on exit.

    *Unified Modeling Language

    Diagrams :Statechart Diagram The most common purpose for use state machine:Modeling the lifetime of an object

    *Unified Modeling Language

    Diagrams :Statechart Diagram Statechart Diagram::A Statechart diagram shows a state machine, emphasizing the flow of control from state to state.

    - Statechart is one of five diagrams to modeling dynamic aspects of system.

    - Activity diagram is a special case of a statechart diagram in which all or most of the states are activity states and all or most of the transitions are triggered by completion of activities in the source state.

    Both activity and statechart are useful in modeling the lifetime of an object. activity diagram: shows flow of control from activity to activity statechart diagram: shows flow of control from state to state.

    - Statechart diagrams commonly contain: 1- simple and composite states 2- transactions, including events and actions

    *Unified Modeling Language

    Diagrams :Statechart Diagram

    Statechart diagram example:

    *Unified Modeling Language

    Diagrams :Component Diagram :A component is a physical and replaceable part of a system that conforms to and provides the realization of a set of interfaces

    - name: 1-simple name 2-path name

    *Unified Modeling Language

    Diagrams :Component Diagram components and classes:Similarities:1-both may realize a set of interfaces2-both may participate in dependency, generalization and association relationship3-both may be nested4-both may have instances5-both may be participants in interactions

    Difference:classes represent logical abstraction; component represent physical thing.components may live on nodes, classes may not.

    *Unified Modeling Language

    Diagrams :Component DiagramBinary replaceability:- A component is substitutable. Support previous interfaces and provide new services through other services.Goal: create a system out of components and then evolve that system by adding new component and replacing old ones, without rebuilding the system.

    Kind of components:1- deployment components: necessary and sufficient to form an executable system, such as DLLs and EXEs.2- work product components: are essentially the residue of the development process, consisting of things such as source code files and data files.3- execution components: are created as a consequence of an executing system. Such as a COM+ object, which is instantiated from a DLL.

    Components stereotypes:1- executable: a component that may be executed on a node2- library: a static or dynamic object library3- table: a component that represents a database table4- file: a component that represents a document containing source code or data5- document: a component that represents a document

    *Unified Modeling Language

    Diagrams :Component Diagram :A component diagram shows a set of components and their relationships.- Modeling the physical aspect of OO systems - Shows the organization and dependencies among a set of components.

    Contents: 1-components 2-interfaces 3-realationships

    *Unified Modeling Language

    Diagrams :Deployment Diagram :A node is a physical element that exists and represents a computational resource, generally having at least some memory and often, processing capability.

    - name: 1-simple name 2-path name

    *Unified Modeling Language

    Diagrams :Deployment Diagram nodes and components:Similarities:2-both may participate in dependency, generalization and association relationship3-both may be nested4-both may have instances5-both may be participants in interactions

    Difference:- Components are things that participate In execution of a system; nodes are Things that execute components- Components represent the physical packaging of otherwise logical elements; nodes represent the physical deployment of components

    *Unified Modeling Language

    Diagrams :Deployment Diagram Connections:The most common kind of relationship between nodes is an association.

    *Unified Modeling Language

    Diagrams :Deployment Diagram :A deployment diagram is a diagram that shows the configuration of run time processing nodes and the components that live on them.

    Contents: 1-nodes 2-relationships - dependency - association

    *Unified Modeling Language

    UML Extension Mechanism

    Lightweight Extension Mechanism

    Heavyweight Extension Mechanism

    *Unified Modeling Language

    Lightweight Extension Mechanism

    Constraints

    Tagged Values

    Stereotypes

    *Unified Modeling Language

    Constraints (OMG Description)

    *Unified Modeling Language

    Constraints

    *Unified Modeling Language

    Tagged Values (OMG Description)

    *Unified Modeling Language

    Tagged Values

    *Unified Modeling Language

    Stereotypes (OMG Description)

    *Unified Modeling Language

    Stereotypes Decorative

    Descriptive

    Restrictive

    Redefined

    Evolutionary

    *Unified Modeling Language

    Stereotypes

    *Unified Modeling Language

    in Conclusion UML:1- UML2- UML3- Multithread4- Design patterns5- UML RUP

    End