Chapter 5 Implementing UML Specification (Part II) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Programming Languages and Paradigms
Written by: Dr. JJ Shepherd
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
© 2006 ITT Educational Services Inc. SE350 System Analysis for Software Engineers: Unit 9 Slide 1 Appendix 3 Object-Oriented Analysis and Design.
1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
Interaction Diagrams Activity Diagram State Machine Diagram
Introduction To System Analysis and Design
1 © Wolfgang Pelz UML2 UML Part Two. 2 © Wolfgang Pelz UML2 Chapters Four & Twelve Interaction Diagrams.
Chapter 8: Modelling Interactions and Behaviour
L26-S1 Interactions 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I.
1 © Wolfgang Pelz UML2 UML Part 3. 2 © Wolfgang Pelz UML2 Chapter Ten State Machine Diagrams.
State Change Modelling. Aim: To introduce the concept and techniques for describing the changes in state that may occur to an object in its lifetime.
Advanced Behavioral Modeling
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
UML Sequence Diagrams Michael L. Collard, Ph.D. Department of Computer Science Kent State University.
State and Sequence Diagrams Modelling dynamic information So far we have seen: Use Case Diagrams – requirements capture, interface.
1 Chapter 5 Implementing UML Specification (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
Chapter 6 View Alignment Techniques and Method Customization (Part II)
Chapter 10 State Machine Diagrams
Object-Oriented Software Testing. C-S 5462 Object-Oriented Software Testing Research confirms that testing methods proposed for procedural approach are.
Copyright by Dr. Clarence Lau, IVE(TY)
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Chapter 8: Modelling Interactions and Behaviour UML Activity Diagram
1 Object-Oriented Modeling Using UML (2) CS 3331 Fall 2009.
Chapter 5 Implementing UML Specification (Part II) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 25. Review Design Level Class Diagram Identifying classes/Operations/Attributes Associations – Simple associations.
1 WXGC6102: Object-Oriented Techniques Modelling Concepts References: Chapter 5 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design.
Introduction To System Analysis and Design
Systems Analysis and Design in a Changing World, 6th Edition
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Object-Oriented Modeling Using UML CS 3331 Section 2.3 of Jia 2003.
Y2 eProjects Session 4 – Advanced Topics. Objectives  Dynamic Models  Design Patterns (Optional)  Software testing (for S4) ACCP i7.1\Sem3_4\eProject\T4.
Chapter 6 Programming Languages © 2007 Pearson Addison-Wesley. All rights reserved.
CPS120: Introduction to Computer Science Decision Making in Programs.
The Unified Modeling Language Part II Omar Meqdadi SE 2730 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Course Instructor: Kashif Ihsan 1. Chapter # 3 2.
2Object-Oriented Program Development Using C++ 3 Basic Loop Structures Loops repeat execution of an instruction set Three repetition structures: while,
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour UML Sequence Diagram.
WXGC6102: Object-Oriented Techniques Object Interaction – Interaction Overview Diagrams Timing Diagrams References: Chapter 9 of Bennett, McRobb and Farmer:
COP 4331 OO Processes for Software Development Lab1 © Dr. David A. Workman School of EE and Computer Science University of Central Florida May 11, 2005.
WXGC6102: Object-Oriented Techniques Specifying Control References: Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design.
UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.
12 Chapter 12: Advanced Topics in Object-Oriented Design Systems Analysis and Design in a Changing World, 3 rd Edition.
CS3773 Software Engineering Lecture 06 UML State Machines.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
Chapter 3: Introducing the UML
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
1 Chapter 11 Global Properties (Distributed Termination)
1 7 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 7 The Object-Oriented Approach to Requirements.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Sequence diagrams Lecture 5. Main terms  Interaction  Life line  Activation  Executable behavior and derived behavior  Messages  Trajectory  Frame.
1 Chapter 5 Implementing UML Specification (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
Chapter 1 Overview of UML for Java Programmers. 2 Outline Diagram Types Diagram Types Class Diagrams Class Diagrams Object Diagrams Object Diagrams Sequence.
Chapter 4 The If…Then Statement
The Movement To Objects
State Machine Diagrams
Interactions.
Program Flow.
Recursive Objects Singly Linked Lists.
Presentation transcript:

Chapter 5 Implementing UML Specification (Part II) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence S.W. Lau and Y.K. Leung McGraw-Hill Education (Asia), 2005

2 Activity Diagrams An activity diagram is used to represent a sequence of actions performed in an activity or a procedure. It can also be used to model an algorithm, the computation flow of a control object or a subsystem. In general, there are two approaches for implementing an activity diagram: Implementing the control flow using the location within a program to hold the state of an object. Control statements, such as if-then-else statement and while statement, are used to implement the necessary branching and looping of the control flow of the activity diagram. Implementing the control flow as a state machine.

3 Activity Diagrams (cont’d) The following are the general rules for translating the elements of an activity diagram into program code: Action state. It is translated to statements of actions, such as method calls, computational statements. Conditional branch. It is translated to an if-then- else statement. Concurrent branch. It is translated to threads for each additional control flow. Loop. A loop in the activity diagram is translated to a while-loop statement.

4 Activity Diagrams (cont’d)

5 Example – Control Object of the Simplified Vending Machine while (true) { amount = 0.0; while (amount < price) { wait for a coin; add coin value to amount; } show all available soft drink; while (selection is not done) { wait for selection from user; if selection is “eject coins” { dispense coins; set selection to “done”; } else if selection is a valid soft drink { dispense change & soft drink concurrently; set selection to “done” }

6 State Diagrams A state diagram is typically used to model the dynamic behavior of a subsystem, a control object or even an entity object. Like activity diagrams, there are two approaches to implement a state diagram: Using the location within a program to hold the state (for implementing active object or entity). Using an explicit attribute to hold the state (for implementing inactive object or entity).

7 State Diagrams (cont’d) The second approach is suitable for implementing the state diagram of an inactive entity. We can implement the state diagram by applying the techniques below: Map the state diagram on to a class. Add a state attribute for storing the state information. Map an event to a method and embed all required state transitions and actions of the event in the method.

8 State Diagrams (cont’d) public void event_n(….) { switch (state) { case state_k: if (guard_condition_w) { state = state_m; perform actions of the transition; } break; case state_v: … } 

9 State Diagrams (cont’d) For a composite state with sequential substates, we can create a nested (inner) class for implementing the sequential substates. The parent state machine can then invoke the method of the nested class for handling transitions within the nested state diagram. Another way to implement the composite state is to transform the parent state diagram to eliminate the composite state so that it becomes a flat level state diagram. For a composite state with concurrent substates, we can create a nested class for implementing each substate. The implementation is similar to that for nested state diagrams. The composite state is exited when all the concurrent substates reach their final states.

10 Example – Control Object of Vending Machine

11 Example – Control Object of Vending Machine (cont’d) class VendingMachineControl { int _state; float _amount, _price; static final int WaitingCoin = 1; static final int WaitingSelection = 2; static final int DispensingSoftDrink = 3; static final int DispensingChange = 4; static final int EjectingCoins = 5;

12 Example – Control Object of Vending Machine (cont’d) public VendingMachineControl(float price) { _amount = 0; _state = WaitingCoin; _price = price; }

13 Example – Control Object of Vending Machine (cont’d) public void insertedCoin(float coinValue) { if (state == WaitingCoin) { amount += coinValue; if (amount >= price) { // fire transition state = WaitingSelection; show available soft drinks; } } // insertedCoin

14 Example – Implementing a State Diagram with Sequential Substates

15 Example – Implementing a State Diagram with Sequential Substates (cont’d) class DispenseControl { int _state; static final int DispensingSoftDrink = 1; static final int DispensingChange = 2; static final int Complete = 3; public dispenseControl() { _state = DispensingSoftDrink; }

16 Example – Implementing a State Diagram with Sequential Substates (cont’d) public boolean dispensedSoftDrink() { if (_state == DispensingSoftDrink) { _state = DispensingChange; dispense change; } return false; }

17 Example – Implementing a State Diagram with Sequential Substates (cont’d) public boolean dispensedChange() { if (_state == DispensingChange) { _state = Complete; return true; } return false; }

18 Example – Implementing a State Diagram with Sequential Substates (cont’d) class VendingMachineControl {..declaration of state attribute, constants, other attributes; declaration of inner class dispenseControl;..public VendingMachineControl(float price) { _amount = 0; _state = WaitingCoin; _price = price; _substate = new DispenseControl(); }

19 Example – Implementing a State Diagram with Sequential Substates (cont’d) public void dispensedSoftDrink() // VendingMachineControl { if (_state == Dispensing) { boolean isComplete = _substate.dispensedSoftDrink(); }

20 Example – Implementing a State Diagram with Sequential Substates (cont’d) // VendingMachineControl public boolean dispensedChange() { if (_state == Dispensing) { boolean isComplete = _substate.dispensedChange(); if (isComplete) { amount = 0; _state = WaitingCoin; }

21 Sequence Diagrams In a sequence diagram, the collaborating objects communicate with each other through messages. A message can be an invocation of a method or an actual message sent from the originating object to the target object. When an object receives a message, it may in turn send out one or more messages to other objects.

22 Sequence Diagrams (cont’d) We can translate a sequence diagram into code by using the following techniques: Translate a message to an appropriate method call. For example, a creation message is translated to a call to the constructor of the target object’s class, i.e. a new statement in Java. Implement methods for handling incoming messages in the target object’s class (see Figure 5.45). Map conditional branchings to conditional statements, such as if-else statement. Implement active objects using threads. Map concurrent branching using concurrent threads.

23 Sequence Diagrams (cont’d) ClassB { ClassC o3; ClassD o4; method1(…) { o3.method2(..); o4.method3(..); }