PETRI NETS REPRESENTATION OF 2 DINING PHILOSOPHERS * * *(F2) T1 T2 *(F1) E2 E1 1 WARNIER-ORR NOTATION It is similar to Jackson charts but uses braces to show chunks (boxes in figures below). Step1A Step1 program Step1A1 Step1A2 Step1B Step1C Step2 Step3A Step3B Step3C If-then-else construct can be represented as Condition ? true case action Step3 Arbitrary label + Complementary Condition ? While loop can be indicated by Arbitrary label (condition, W) For example, Polled loop (flag=0, W) false case action statement check flag Repeat until loop is represented similarly but U is used instead of W. Indexed loop is represented by Arbitrary label (n) statement For example, addition of 100 numbers assuming that initially i=1, s=0 Add numbers (100) s=s+n[i] i=i+1 Automatic telling machine may be represented by Withdraw? + Correct? “ Function?” Query? + “Enter PIN#?” + Deposit? Wrong? Sorry valid? Remit cash + invalid? Sorry display balance ‘Amount?’ “Amount?” accept envelope 2 STATE CHARTS Can depict synchronous and asynchronous operations (broadcast communication). If state Y consists of AND components A and B, Y is called the orthogonal product of A and B, and if Y is entered from the outside, then states A and B are entered simultaneously (if not specified other). May be represented chain reaction; that is, events can trigger other events. H A C e/f E f/g B D g F Chain reaction of length 2 is represented. g D A g(e) f p B C h f f State D enters state A, when event g occurs, or state B, if event p occurs. State B is entered from state A when event f occurs. State C can be entered from state A if event g occurs and condition e holds. In this case event g at first causes entering to A, and next occurrence can cause transition to C. In general case one event can cause multiple transitions in parallel sub processes. 3 UNIFIED MODELING LANGUAGE UML is accepted by the Object Management Group (OMG) as the standard for modeling object oriented programs. Types of UML Diagrams UML defines nine types of diagrams: class (package), object, use case, sequence, collaboration, statechart, activity, component, and deployment. Class diagrams are the backbone of almost every object oriented method, including UML. They describe the static structure of a system. Package diagrams are a subset of class diagrams, but developers sometimes treat them as a separate technique. Package diagrams organize elements of a system into related groups to minimize dependencies between packages. Object diagrams describe the static structure of a system at a particular time. They can be used to test class diagrams for accuracy. Use case diagrams model the functionality of system using actors and use cases. Sequence diagrams describe interactions among classes in terms of an exchange of messages over time. Collaboration diagrams represent interactions between objects as a series of sequenced messages. Collaboration diagrams describe both the static structure and the dynamic behavior of a system. Statechart diagrams describe the dynamic behavior of a system in response to external stimuli. Activity diagrams illustrate the dynamic nature of a system by modeling the flow of control from activity to activity. An activity represents an operation on some class in the system that results in a change in the state of the system. Component diagrams describe the organization of physical software components, including source code, run-time (binary) code, and executables. Deployment diagrams depict the physical resources in a system, including nodes, components, and connections. 4 UML CLASS DIAGRAMS Class diagrams are the backbone of almost every object-oriented method including UML. They describe the static structure of a system. Classes represent an abstraction of entities with common characteristics. Associations represent the relationships between classes. Illustrate classes with rectangles divided into compartments. Place the name of the class in the first partition, list the attributes in the second partition, and write operations into the third. Classes may be abstract – have only interface without implementation (useful for platform independent applications). Abstract classes are shown with label {abstract} Use visibility markers to signify who can access the information contained within a class. Private visibility hides information from anything outside the class partition. Public visibility allows all other classes to view the marked information. Protected visibility allows child classes to access information they inherited from a parent class. 5 UML CLASS DIAGRAMS (CONT 1) Associations represent static relationships between classes. Place association names above, on, or below the association line. Place roles near the end of an association. Roles represent the way the two classes see each other. Note:It's uncommon to name both the association and the class roles. Multiplicity (Cardinality) Place multiplicity notations near the ends of an association. These symbols indicate the number of instances of one class linked to one instance of the other class. For example, one company will have one or more employees, but each employee works for one company only. Constraint Place constraints inside curly braces {}. Constraints are assertions, i.e. Boolean statements which are to be true always for the system 6 UML CLASS DIAGRAMS (CONT 2) Navigability – is shown by arrows on association. It Class1 points to Class2, it means that Class1 is responsible for output information on associated objects of Class2. Associations without arrows are treated as unknown or bidirectional navigability. If there is no name of association end, by default may be used name of the attached class. Composition and Aggregation Aggregation is a part-of relationship (car has an engine, building has floors, etc.). Composition is a special type of aggregation that denotes a strong ownership between Class A, the whole, and Class B, its part. With composition part object may belong to only one whole; parts are usually expected to live and die with the whole. Any deletion of the whole cascades to the parts. Illustrate composition with a filled diamond. Use a hollow diamond to represent a simple aggregation relationship, in which the "whole" class plays a more important role than the "part" class, but the two classes are not dependent on each other. The diamond end in both a composition and aggregation relationship points toward the "whole" class or the aggregate. 7 UML CLASS DIAGRAMS (CONT 3) Generalization Generalization is another name for inheritance or an "is a" relationship. It refers to a relationship between two classes where one class is a specialized version of another. For example, Honda is a type of car. So the class Honda would have a generalization relationship with the class car. 8 UML PACKAGE DIAGRAMS Package diagrams organize the elements of a system (classes) into related groups to minimize dependencies among them Packages Use a tabbed folder to illustrate packages. Write the name of the package on the tab or inside the folder. Similar to classes, you can also list the attributes of a package. Visibility Visibility markers signify who can access the information contained within a package. Private visibility means that the attribute or the operation is not accessible to anything outside the package. Public visibility allows an attribute or an operation to be viewed by other packages. Protected visibility makes an attribute or operation visible to packages that inherit it only. 9 UML PACKAGE DIAGRAMS(CONT 1) Dependency Dependency defines a relationship in which changes to one package will affect another package. Importing is a type of dependency that grants one package access to the contents of another package. Dependency between 2 packages exists if any dependency exists between any 2 classes in the packages. If P1>P2, it means that package P1 depends on package P2. 10 UML OBJECT DIAGRAMS Object diagrams are also closely linked to class diagrams. Just as an object is an instance of a class, an object diagram could be viewed as an instance of a class diagram. Object diagrams describe the static structure of a system at a particular time and they are used to test the accuracy of class diagrams. Object names Each object is represented as a rectangle, which contains the name of the object and its class underlined and separated by a colon. Object attributes As with classes, you can list object attributes in a separate compartment. However, unlike classes, object attributes must have values assigned to them. Multiplicity You can illustrate multiple objects as one symbol if the attributes of the individual objects are not important. 11 UML OBJECT DIAGRAMS (CONT 1) Links Links are instances of associations. You can draw a link using the lines used in class diagrams. Self-linked Objects that fulfill more than one role can be self-linked. For example, if Mark, an administrative assistant, also fulfilled the role of a marketing assistant, and the two positions are linked, Mark's instance of the two classes will be selflinked. Object diagram may be considered as collaboration diagram but without messages. Party children * -location Person Organization parent 1 12 UML OBJECT DIAGRAMS (CONT 2) engineering:Organization -location : <unspecified> = Boston End1 Parent apps:Organization tools:Organization -location : <unspecified> = Saba -location : <unspecified> = Chicago Parent Don:Person John:Person -location : <unspecified> = Champaign -location : <unspecified> = Champaign UML USE CASE DIAGRAMS Use case diagrams model the functionality of a system using actors and use cases. Use cases are services or functions provided by the system to its users. System Draw your system's boundaries using a rectangle that contains use cases. Place actors outside the system's boundaries. Use Case Draw use cases using ovals. Label ovals with verbs that represent the system's functions. 13 UML USE CASE DIAGRAMS (CONT 1) Actors Actors are the users of a system. When one system is the actor of another system, label the actor system with the actor stereotype. Relationships Illustrate relationships between an actor and a use case with a simple line. For relationships among use cases, use arrows labeled either "uses" or "extends." A "uses" relationship indicates that one use case is needed by another in order to perform a task (is used to avoid repeating). An "extends" relationship indicates alternative options under a certain use case (is used to describe a variation on normal behaviour). 14 UML USE CASE DIAGRAMS (CONT 2) UML SEQUENCE DIAGRAMS Sequence diagrams describe interactions among classes in terms of an exchange of messages over time. Class roles describe the way an object will behave in context. Use the UML object symbol to illustrate class roles, but don't list object attributes. 15 UML SEQUENCE DIAGRAMS (CONT 1) Activation Activation boxes represent the time an object needs to complete a task. Messages Simple (flat) – the message doesn’t expect a reply, control passes from sender to receiver; synchronous (call) – normal procedural situation – sender loses control until the receiver finishes handling the message, then gets control back (may be optionally shown as return – dashed arrow; asynchronous – message doesn’t expect a reply, but unlike flat case, the sender stays active and may send further messages. 16 UML SEQUENCE DIAGRAMS(CONT 2) Lifelines Lifelines are vertical dashed lines that indicate the object's presence over time. Destroying Objects Objects can be terminated early using an arrow labeled "< < destroy > >" that points to an X. 17 UML SEQUENCE DIAGRAMS(CONT 3) Loops A repetition or loop within a sequence diagram is depicted as a rectangle. Place the condition for exiting the loop at the bottom left corner in square brackets [ ]. 18 UML COLLABORATION DIAGRAMS A collaboration diagram describes interactions among objects in terms of sequenced messages. Collaboration diagrams represent a combination of information taken from class, sequence, and use case diagrams describing both the static structure and dynamic behavior of a system. Class roles Class roles describe how objects behave. Use the UML object symbol to illustrate class roles, but don't list object attributes. Association roles Association roles describe how an association will behave given a particular situation. You can draw association roles using simple lines labeled with stereotypes. Messages Collaboration diagrams do not have an explicit way to denote time and instead number messages in order of execution. Sequence numbering can become nested. For example, nested messages under the first message are labeled 1.1, 1.2, 1.3. Condition for a message is placed in square brackets following the sequence number. An * after the sequence number to indicate a loop. 19 UML COLLABORATION DIAGRAMS(CONT 1) UML STATECHART DIAGRAMS A statechart diagram shows the behavior of classes in response to external stimuli. This diagram models the dynamic flow of control from state to state within a system. States States represent situations during the life of an object. You can easily illustrate a state in SmartDraw by using a rectangle with rounded corners. 20 UML STATECHART DIAGRAMS (CONT 1) Transition A solid arrow represents the path between different states of an object. Label the transition with the event that triggered it and the action that results from it. Initial State A filled circle followed by an arrow represents the object's initial state. Final State An arrow pointing to a filled circle nested inside another circle represents the object's final state. Synchronization and Splitting of Control A short heavy bar with two transitions entering it represents a synchronization of control. A short heavy bar with two transitions leaving it represents a splitting of control that creates multiple states. 21 UML STATECHART DIAGRAMS (CONT 2) UML ACTIVITY DIAGRAMS An activity diagram illustrates the dynamic nature of a system by modeling the flow of control from activity to activity. An activity represents an operation on some class in the system that results in a change in the state of the system. Typically, activity diagrams are used to model workflow or business processes and internal operation. Because an activity diagram is a special kind of statechart diagram, it uses some of the same modeling conventions. Action states Action states represent the noninterruptible actions of objects. You can draw an action state in SmartDraw using a rectangle with rounded corners. 22 UML ACTIVITY DIAGRAMS(CONT 1) Action Flow Action flow arrows illustrate the relationships among action states. Object Flow Object flow refers to the creation and modification of objects by activities. An object flow arrow from an action to an object means that the action creates or influences the object. An object flow arrow from an object to an action indicates that the action state uses the object. Initial State A filled circle followed by an arrow represents the initial action state. Final State An arrow pointing to a filled circle nested inside another circle represents the final action state. 23 UML ACTIVITY DIAGRAMS (CONT 2) Branching A diamond represents a decision with alternate paths. The outgoing alternates should be labeled with a condition or guard expression. You can also label one of the paths "else." Synchronization A synchronization bar helps illustrate parallel transitions. Synchronization is also called forking and joining. 24 UML ACTIVITY DIAGRAMS(CONT 3) Swimlanes Swimlanes group related activities into one column. Each swimlane is labeled by responsible for it class. Example of order processing follows: 25 UML COMPONENT DIAGRAMS A component diagram describes the organization of the physical components in a system. Component A component is a physical building block of the system. It is represented as a rectangle with tabs. Interface An interface describes a group of operations used or created by components. Dependencies Draw dependencies among components using dashed arrows. They show how changes to one component may cause other components to change. This includes also communication and compilation dependencies. UML DEPLOYMENT DIAGRAMS Deployment diagrams depict the physical resources in a system including nodes, components, and connections. 26 UML DEPLOYMENT DIAGRAMS (CONT 1) Node A node is a physical resource that executes code components. Association Association refers to a physical connection between nodes, such as Ethernet, they show communication paths over which the system will interact. Components and Nodes Place components inside the node that deploys them. 27 UML DEPLOYMENT DIAGRAMS (CONT 2) f 28