Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2003 v4.1 01/01/2003 E2-1 Essential Rhapsody in C++ Part Two Case Study.

Slides:



Advertisements
Similar presentations
Interaction Design: Visio
Advertisements

Computer Basics Hit List of Items to Talk About ● What and when to use left, right, middle, double and triple click? What and when to use left, right,
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
Essential Rhapsody in C++
Tutorial 8: Developing an Excel Application
Annotation & Nomenclature By Corey Fortezzo for PG&G GIS Workshop, 2010.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Bas-1 Essential Rhapsody in C++ Section 2 Basic Level.
XP Information Technology Center - KFUPM1 Microsoft Office FrontPage 2003 Creating a Web Site.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Road Map Introduction to object oriented programming. Classes
© I-Logix Rhapsody C++ V /01/2004 E1-1 Exercise 2 : Count Down.
אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט1 פרק 8 נקודות חשובות בתרגילים 7-9.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level Modified.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Level Concurrency.
Customizing Word Microsoft Office Word 2007 Illustrated Complete.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
© I-Logix Rhapsody C++ V /01/2004 E1-1 Exercise 3 : Dishwasher.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Int-1 Essential Rhapsody in C++ Section 3 Intermediate Level.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Level Multiplicity.
C++ fundamentals.
Microsoft ® Office PowerPoint ® 2003 Training Playing movies [Your company name] presents:
Academic Computing Services 2010 Microsoft ® Office Visio ® 2007 Training Get to know Visio.
With Alex Conger – President of Webmajik.com FrontPage 2002 Level I (Intro & Training) FrontPage 2002 Level I (Intro & Training)
Laboratory Exercise # 3 – Basic File Management Office Productivity Tools 1 Laboratory Exercise # 3 Basic File Management Objectives: At the end of the.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
HBar OR Reader Documentation A copy of the PowerPoint Viewer is shipped with the HBar OR Reader on the HBar Official Records [OR] CD. The PowerPoint Viewer.
PROG Mobile Java Application Development PROG Mobile Java Application Development Event Handling Creating Menus.
A First Program Using C#
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
1 I-Logix Professional Services Specialist Rhapsody IDF (Interrupt Driven Framework) CPU External Code RTOS OXF Framework Rhapsody Generated.
Teach Yourself Windows 98 Module 2: Working with Files, Folders, and the Desktop.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Introduction to the WebBoard Terry Dennis. The WebBoard - Our Connection The WebBoard URL is
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
CHAPTER 9 Introducing Microsoft Office Learning Objectives Start Office programs and explore common elements Use the Ribbon Work with files Use.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
Spreadsheets in Finance and Forecasting Presentation 9 Macros.
Prepared by: Sanaz Helmi Hoda Akbari Zahra Ahmadi Sharif University of Tech. Summer 2006 An Introduction to.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
In the next step you will enter some data records into the table. This can be done easily using the ‘Data Browser’. The data browser can be accessed via.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Basic Editing Lesson 2.
XP New Perspectives on Windows 2000 Professional Windows 2000 Tutorial 2 1 Microsoft Windows 2000 Professional Tutorial 2 – Working With Files.
GISMO/GEBndPlan Overview Geographic Information System Mapping Object.
Programming in Java CSCI-2220 Object Oriented Programming.
1 Class Diagrams. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are for visualizing, specifying and documenting.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
© I-Logix Rhapsody C++ V /01/2004E1-1 “Essential” Tool Training Basic Rhapsody Basic Rhapsody Rhapsody in C++ V /01/04.
When the program is first started a wizard will start to setup your Lemming App. Enter your company name and owner in the fields designated “Company Name”
Navigation: If the tutorial opens up in your web browser, simply click your mouse to advance to the next slide. Use the “Backspace”
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting.
Active-HDL Server Farm Course 11. All materials updated on: September 30, 2004 Outline 1.Introduction 2.Advantages 3.Requirements 4.Installation 5.Architecture.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
IBM Rational Rhapsody Advanced Systems Training v7.5
Microsoft® Office FrontPage® 2003 Training
Introducing Microsoft Office 2010
Analysis models and design models
Essential Rhapsody in C++
Presentation transcript:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-1 Essential Rhapsody in C++ Part Two Case Study

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-2 Case Study : Cash Register

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-3 Cash Register Requirements A cash register needs to be designed that reads barcodes of products that a customer has selected. When a product has been identified, its name and price are displayed on a display. If the barcode cannot be read automatically then the message "Unknown product" will be displayed and the barcode can be entered via the cashier’s keyboard. When all the selected products have been read, a ticket is generated containing the list of all the selected products with the unit price, quantity and total price. Some products can be on special offer. It should be possible to add special offers such as "Buy one get one free", "10% off“ or "Buy 3 for 1 Euro". A keyboard allows the cashier to start a session, cancel the last selected product, end a session and issue a ticket.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-4 Part Two Case Study Use Case Analysis

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-5 Rapid Object oriented Process for Embedded Systems (ROPES) In order to implement this Cash Register, we are going to be using the ROPES process: More information on the ROPES process can be found in the book “Doing Hard Time” by Bruce Powel Douglass. ISBN

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-6 Before we start During this case study, there will be times where we need to enter several non-trivial descriptions and operation implementations. In order to reduce the typing, a report of the final model “CashRegister” can be supplied so that descriptions and implementations can be cut and pasted from this file. During the course in order to optimize the allocated time, it is not necessary to enter descriptions, but in a real project it is very important to enter them. If no descriptions are entered then the final documentation will be a lot less useful!

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-7 Use cases and actors From the requirements find use cases and actors. Group Exercise!

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-8 Project Description Create a new project called CashRegister. Note that we could add a description for the project.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-9 Hyperlinks We could also add hyperlinks into our description in order to reference external documents or web pages:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-10 Principal Use Cases Add a use case diagram entitled “Principal Uses” Add use cases and actors : Use Case Actor

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-11 Actors description We could add descriptions for the actors: –Customer: –Cashier: –Manager:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-12 Principal use case description We could add a description to our principal use case “Sum the cost of selected products”:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-13 Principal use case description We could also add a description to our other principal use case “Configure the products”:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-14 Secondary Use Cases Add another use case diagram entitled “Secondary Uses”. Add the three new use cases and dependencies Drag this use case from the browser Double-click on each dependency and set the stereotype >

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-15 The browser The browser should now look like this:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-16 Secondary Use cases 1: For the secondary use case “Keep count of selected products” we could add the description:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-17 Secondary Use cases 2: For the secondary use case “Generate a ticket showing total cost” we could add the description:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-18 Secondary Use cases 3: For the secondary use case “Manage special offers” we could add the following description:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-19 Analysis Package All the use cases, actors, and diagrams that we have currently created are in a package called “Default”, we can rename this to something more meaningful. Use the features menu to rename the package “Default” to “AnalysisPkg” A package in UML is similar to a folder in Windows. It is used to organize the model. Packages can be nested. Model elements can be moved from one package to another.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-20 Navigation In order to navigate within our model, we can set the main diagram for our main use case to be the “Secondary Uses” diagram. Now from our “Principal Uses” diagram we can navigate to our “Secondary Uses” diagram. We can also set the main diagram for our AnalysisPkg to be the “Principal Uses” diagram.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-21 Part Two Case Study Finding Objects

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-22 Brainstorming to find objects Spend a few minutes and come up with a list of possible objects: Find some classes and a short description for each one about their responsibility Think about possible relations between these classes Should we use generalization? Are any classes reactive? Are any classes active? Group Exercise!

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-23 Use case driven approach We’ll attack this problem one use case at a time. Doing the use cases in this order: 1.Configure the products 2.Keep count of selected products 3.Generate a ticket showing total cost 4.Manage special offers When doing this case study, each student should progress at their own speed and in the allocated time should be able to complete at least the first two use cases. The last two use cases are really extended exercises for the faster students.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-24 CashRegister package Add a new package called “CashRegisterPkg” We have an Object Model Diagram that we have not used. Rename it to “CashRegister Overview” and then move it into our package “CashRegisterPkg” To move the OMD, simply grab it in the browser and drag it onto the CashRegisterPkg package.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-25 Use the Show option in the relation features window for the Role name CashRegister Overview Add classes and directed relations to the “CashRegister Overview” OMD. Note multiplicity * (many)

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-26 Classes Responsibilities We could add descriptions for these classes:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-27 Part Two Use Case 1 “Configure the products”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-28 Use case 1: Configure the products Within the CashRegisterPkg add a new OMD called “ProductDatabase Overview” Set up the main diagram for the ProductDatabase class to point to this diagram. (Useful for navigating)

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-29 Product attributes Add attributes to the Product class: For the attribute name, since const char* is not an existing type, you must untick the box and enter the declaration manually.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-30 Product public constructor Add a constructor to initialize the Product: Add arguments and Initializer

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-31 Product protected constructor Add a protected constructor to stop the Product being created without any arguments: To stop the default constructor from being generated we could have set the property CG->Class->GenerateImplicitConstructors If you wanted to display the constructors like they’re shown here, then you could use the Display Options.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-32 Generated code Switch on the “active code view” and select the relation between the ProductDatabase and the Product class. active code view

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-33 OMCollection pros/cons When the multiplicity for a relation is * (many) then Rhapsody generates a collection using the template class OMCollection This is similar to a bag. We can put many products in it and also take them out. Advantages: –Fast access to a particular element –Adding elements is fast, since memory pre-allocated –Safe, will dynamically allocate more memory if needed Disadvantages: –The order is not specified. –By default pre-allocates 20 pointers –Uses templates, which some compilers handle inefficiently The default number of pointers can of course be changed to a smaller or larger number.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-34 OMCollection overview

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-35 Ordered property Set the Ordered property for the relation to True.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-36 OMList pros/cons When the multiplicity for a relation is * (many) and the property Ordered is True, then Rhapsody generates a linked list using the template class OMList Advantages: –Efficient use of memory –Order is specified –Safe, will dynamically allocate more memory if needed Disadvantages: –Access to a particular element is slow –Adding elements is slow since memory must be allocated –Uses templates, which some compilers handle inefficiently

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-37 OMList overview

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-38 Qualified Association A responsibility of the ProductDatabase class is to allow other classes to find a product given a barcode. It is possible that we may have 1000’s of products and we will want to be able to lookup a product as quickly as possible. To do so we want to qualify our relation with the barcode. Tick this box Select the attribute barcode

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-39 Generated code It is not necessary to set the ordered property, this has no effect on a qualified association.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-40 OMMap pros/cons When the multiplicity for a relation is * (many) and the relation is qualified with a key, then Rhapsody generates a map using the template class OMMap Advantages: –Lookup of an element using the key is fast –Efficient use of memory –Order is specified according to the value of the key –Safe, will dynamically allocate more memory if needed Disadvantages: –Adding elements is slow since memory must be allocated and the map rebalanced –Uses templates, which some compilers handle inefficiently

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-41 OMMap overview This is a balanced tree, so searching is as fast as possible.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-42 Generated operations When we look at the code, Rhapsody has generated two useful operations –void addItsProduct(int,Product*) –Product* getItsProduct(int) We can use the first to add products to our map, and the second to get a product given a specific barcode.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-43 Creating products Create a constructor for ProductDatabase that does the following:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-44 Build Package In order to try this out let’s create a new package called “BuildPkg”. This package will contain the classes that are needed to build our CashRegister. Copy the “CashRegister overview” diagram from the CashRegisterPkg to the BuildPkg (hold the ctrl key down and drag it in the browser) Rename the copied diagram to “Build Overview”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-45 Build Prototype Add a composite class called BuildPrototype around all our classes except the Product class on the “Build Overview” diagram.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-46 Initial instances The responsibility of the BuildPrototype class is to instantiate our objects and initialize the relations between them. If any classes become reactive, it will also start their behavior. Any classes that are reactive will also run on the same thread as the composite class. If the composite class is deleted then it will also delete the objects that it created.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-47 Creating initial instances Use the features menu for each class inside the composite class to create initial instances: Instances of the Product class will get created by the ProductDatabase class We don’t need to specify an instance name, Rhapsody will do that for us. Select multiplicity 1 for all classes inside the composite class

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-48 Composite class By default the relations between the composite and its components are directional. They can be made symmetrical through the browser.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-49 Links If a relation is drawn inside the composite class, then that relation will be automatically initialized at run time by Rhapsody. This is known as a link. Rhapsody shows all these links in the browser.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-50 Component Rename the existing component to RhapsodyCashRegister Rename the configuration to Debug Create an initial instance of BuildPrototype and select the tick box Derived Set Environment to Microsoft Set Instrumentation to Animation

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-51 Save / Generate / Make / Run Save & Generate / Make / Run

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-52 Initialized objects Check that we have an initial instance of the BuildPrototype and instances of all the other classes. Note the names of the instances that are inside the composite instance. We should also have five instances of Product

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-53 ProductDatabase The ProductDatabase should know about all the five instances of Product, each of which should be initialized correctly.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-54 Part Two Use Case 2 “Keep count of selected products”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-55 Scenarios For this use case we can create some sequence diagrams which will help us understand how the Cash Register works: For example we’ll look at the following scenarios: 1.Selecting products 2.Cancelling products 3.Manually entering a barcode

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-56 Scenario selecting products Create in the CashRegisterPkg a “Design” sequence diagram entitled “Scenario selecting products”. Drag the classes onto the diagram as shown below:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-57 Starting the scenario Add a condition mark called idle and two partition lines with associated text.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-58 Adding a message Draw a message evStart diagonally from the Keyboard to the CashRegister. Answer Yes to the question.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-59 Adding more operations Add the operations startSession() and show() Add a condition mark “active” Answer Yes to realize the messages

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-60 Event or Primitive operation Since we drew the message evStart diagonally, Rhapsody has added the message evStart to the CashRegister as an event. If you drew the message show horizontally then the message will have been added as a primitive operation. Make sure that evStart is an event and that startSession and show are both primitive operations.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-61 Operation show() Edit the show operation so that it takes an argument aMsg of type const char*

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-62 Adding more operations Add another partition line and more operations Answer Yes to realize the operations

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-63 Return value The operation getProduct returns a Product, we can indicate this by using the features of this message

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-64 Adding more operations Add arguments to evBarcode, identifyProduct, getProduct and addProduct. Add return value for the getProduct operation Answer Yes to realize the operations

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-65 Finishing the scenario Complete the scenario by adding a partition line, an event, three more operations and a condition mark.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-66 Browser Now that the scenario is completed, we have populated our browser, which should look similar to this:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-67 Scenario cancelling products Add another “Design” sequence diagram entitled: “Scenario cancelling products”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-68 Browser This scenario should have added just one more event evCancel, as well as operations removeLastProduct() and isNoMoreProducts() to our browser. Make sure that evCancel is an event

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-69 Implementation We need to start to implement the operations, let’s start with the Display class Add the following implementation for the show operation:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-70 Include Since we have used cout, we should do an include of “iostream.h” or We can use the property ImpIncludes to do this. Set the value of this property for the Display class to With the Visual C++ compiler, we don’t have to do this, but we do for other compilers such as gnu.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-71 CashRegister statechart From our scenarios, we have noted that the CashRegister receives events. We also added a couple of condition marks indicating states. So we need to add a Statechart to the CashRegister. Add the following Statechart, note that since the events already exist, we can right-click and select them from the list.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-72 Completing the Statechart Complete the Statechart: Remember that params is a Rhapsody generated pointer that allows access to the arguments of the event.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-73 Ordered Relation Since we need to be able to remove the last product added, the order of our products is important so we need to make our relation ordered. For the relation itsProduct, set the property ordered to True

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-74 {Ordered} To indicate that this relation is ordered, we can add a Note to indicate this. Add a Note using the icon. As we saw previously, this will generate a linked list.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-75 CashRegister addProduct() Add the implementation to the addProduct() operation of the CashRegister class

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-76 Include stdio.h Since we have used sprintf, we need to include stdio.h, so we can again use the ImpIncludes property to do this for the CashRegister class

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-77 CashRegister endSession() Add the implementation for the endSession() operation: clearItsProduct() is an operation that gets generated automatically and clears (or empties) the linked list.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-78 CashRegister identifyProduct() Add the implementation for the identifyProduct() operation:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-79 CashRegister isNoMoreProducts() Ensure that the isNoMoreProducts() operation returns an int and make it inline and constant. Add the implementation: Operation of OMList to check if list is empty.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-80 CashRegister removeLastProduct() For this operation, we need to iterate through the linked list to get the last product. To do this, we need to use an “iterator”, this is a friend class that allows us to manipulate the list. We will use the following declaration OMIterator iter(itsProduct); This declares iter as being an iterator to a collection/list of Products and is automatically initialized to point to the first Product. At first glance, the syntax for iterators may seem a little complex, but it is soon mastered.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-81 CashRegister removeLastProduct() Add the implementation for the removeLastProduct() operation: removeItsProduct() is an operation that gets generated automatically.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-82 CashRegister startSession() Add the implementation for the startSession() operation:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-83 ProductDatabase getProduct() Finally add an implementation for the getProduct() operation of the ProductDatabase class. Check that it returns a Product* getItsProduct() is an operation that gets generated automatically.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-84 Save / Generate / Make / Run Close all diagrams Save Generate / Make / Run Go Idle Note: Animation View

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-85 Running a scenario Open an animated sequence diagram based on “Scenario selecting products”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-86 Injecting events Check the scenario by injecting events evStart, followed by evBarcode(12345), evBarcode(12346), evCancel and finally evEnd to the CashRegister instance. You won’t see the events, since we didn’t add a system border to this sequence diagram.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-87 Automating the tests We can check that our model is correct by manually injecting events and observing the animated diagrams. Ideally we’d like to automate these tests, this can be done ideally by using the Test Conductor (an add-on product to Rhapsody) Another way to automate these tests is to use an actor to drive our model. We will use our actor “Cashier” to execute several scenarios.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-88 Actor Driven overview Add the following Object Model Diagram to the CashRegisterPkg entitled “Actor Driven Overview” The simplest way to do this, is to drag the actor and classes from the browser onto the OMD.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-89 Actor Statechart Add the following Statechart to the Cashier actor is a junction connector This transition was drawn from the state to the junction connector, then the line shape was changed to rectilinear and a reroute done.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-90 A Sub-Statechart Add the following sub-Statechart for the state sd1_adding_products Use the sub-state connector and name it SD1_COMPLETE

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-91 Another sub-Statechart Add the following sub-Statechart for the state sd2_cancelling_products Use the sub-state connector and name it SD2_COMPLETE

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-92 Sub-Statechart stub connectors Add the Sub-Statechart Stub connectors SD1_COMPLETE and SD2_COMPLETE to the top- level Statechart. Note that the … indicates that there is a sub-state. To connect to the sub-state connector, connect to the centre of the connector.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-93 Keyboard operations Add operations startSession(), endSession() and cancelProduct() to the Keyboard class

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-94 BarcodeReader operation Add operation detect(int aCode) to the BarcodeReader class with implementation:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-95 Creating an instance of an actor Copy the existing configuration Debug then rename to ActorDriven Create an initial instance of Cashier and select “Generate Code For Actors” Make sure that we still have the initial instance of BuildPrototype

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-96 Initializing the relations We must initialize the relations between our actor and the Keyboard and BarcodeReader Set the ActorDriven configuration as the active configuration Save / Generate and Make (don’t run it’ll crash!) Select the ActorDriven configuration and edit the main

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-97 Editing the main Add the extra two lines to initialize the relations and then click on the browser to automatically roundtrip this code into the configuration. For a relation ex: itsKeyboard, operations getItsKeyboard() and setItsKeyboard() will always be generated automatically.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-98 Save / generate / make / run Start the animation and check that there is an instance of the Cashier and its relations are initialized.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-99 Running a scenario Open an animated sequence diagram based on “Scenario selecting products” Generate event evS1 to the Cashier object and hit

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-100 Saving the diagram Stop the animation Close the animated sequence diagram and click Yes to save it

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-101 Comparing sequence diagrams We can now compare the expected scenario against the actual scenario Select “Sequence Diagram Compare” Select the diagrams to compare Click OK

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-102 The Comparison One major difference!

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-103 Correcting the problem Which diagram is wrong? Correct the error and try another comparison Check out the other Actor driven scenario Does our model conform to both scenarios?

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-104 Manually entering a barcode We can now start to look at how we can manually enter a barcode. To facilitate the implementation we will introduce a new class KeyReader which has the following description. Add a new Object Model Diagram entitled “Keyboard Overview”, drag the class Keyboard onto it and add a new class KeyReader. Add a composition relation between them. Set up the main diagram for Keyboard

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-105 Scenario manually entering barcode Add a new sequence diagram “Scenario manually entering a barcode”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-106 Keyboard Statechart Add the following Statechart to the Keyboard

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-107 Keyboard attributes/operations Add an attribute barcode of type int Add implementation for the enterBarcode operation

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-108 Active class We need the KeyReader class to wait for keys, by using “cin >> c” However calling an operation like this will block the execution, so this is a good candidate for making the KeyReader class “active” (so that it runs on it’s own thread). Set the concurrency for the KeyReader class to “active” instead of sequential. The thick border indicates an “active” class

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-109 OMThread Switch on the “Active code view” and note that the KeyReader class inherits from OMThread, this is a Rhapsody framework class. Rhapsody will create a thread for us that will run an operation in OMThread called execute(). We need to overload this operation so that it constantly reads the keys.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-110 Overloading execute() Add an operation execute to the KeyReader class that returns “OMReactive*” and that has the following implementation: We must return “OMReactive*” since this operation must have the same signature as the execute operation in OMThread.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-111 Read operation Add a read(char c) operation with implementation: (c – ‘0’) simply converts an ASCII character between ‘0’ and ‘9’ to an integer between 0 and 9.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-112 Switching off animation Since the execute operation never ends, it doesn’t make sense to animate it. Use the Animate property to disable the execute operation from being animated

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-113 Starting the thread To start our KeyReader thread, we must call the start operation which is part of OMReactive. We can add a constructor to the Keyboard class to do this. If an active class has a Statechart, then there is no need to overload the execute operation or call the start operation, this gets done automatically for us.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-114 Thread properties If we wanted to execute our model on a real target, then we could set various properties for the thread of our KeyReader class such as the priority, name, stack size, message queue size …

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-115 Execution Save / Generate / Make / Run / Go In the DOS console window enter: s 12345b 12347b c e We can now use the keyboard to run scenarios. Check that the model works as expected.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-116 Threads Now that we have an active class we can use the thread button to inspect the threads. We can set the focus of the call stack and event queue to any one thread. Set the focus to the KeyReader thread set focus The call stack shows the actions and the event queue shows the pending events just for the current thread. The animation must be paused to get access to the thread button.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-117 Setting a breakpoint Use the breakpoint command to set a breakpoint when the KeyReader thread gets control Go, then in the DOS console window enter command : c

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-118 Updating the use case Now that we have created some sequence diagrams, we can associate them with the use case “Keep count of selected products”.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-119 Referenced Sequence Diagrams Select the use case “Keep count of selected products” in the browser and add the following sequence diagrams as “Referenced Sequence Diagrams”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-120 Part Two Use Case 3 “Generate a ticket showing total cost”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-121 “Generate a ticket” Use Case In order to generate a ticket, we need to be able to count how many of each product there are. To do so we’ll introduce a new class CountedProduct. Create a new OMD entitled “Product Overview” Set this to be the main diagram for the class Product

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-122 Product Overview Drag the classes CashRegister and Product onto the OMD and add the class CountedProduct Add inheritance and Qualified association Add attribute count of type int Add operation getPrice that returns an int Add operation increment Set Multiplicity *

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-123 CountedProduct For the CountedProduct class: –Add description –Add implementations Initialize count to 1

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-124 CountedProduct constructor We will be creating CountedProducts from Products so we need a constructor that takes a “Product*” as an argument. Add the constructor

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-125 Another Product constructor Add another constructor to the Product class that is protected and that takes a Product* as an argument

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-126 Adding a scenario Add the Sequence Diagram entitled “Scenario generating a ticket” Drag the classes from the browser onto the diagram Double-click on each instance of CountedProduct to enter the specific name of the instance

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-127 Completing the scenario constructor destructor

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-128 Printer Implement the print operation for the Printer class Set property ImpIncludes so that the Printer class will include

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-129 countProducts() operation For the CashRegister class add the implementation for the countProducts() operation Don’t forget that to save typing, text can be cut and pasted from the report.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-130 generateTicket() operation For the CashRegister class add the implementation for the generateTicket() operation

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-131 endSession() operation We need to modify the endSession() operation so that we remove all the CountedProducts and delete them

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-132 Printing a ticket Save Generate / Make / Run Use the DOS console to start a session, enter several barcodes and then end a session

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-133 Using the Actor to print a ticket Add a new state sd3_generating_a_ticket to the Cashier actor so that we can easily test out our model Instead of drawing this new state and sub-state chart, a quicker way is to simply copy one of the other states, then paste it and rename it.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-134 Adding the sub-Statechart Don’t forget that to save typing, text can be cut and pasted from the report.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-135 Executing the scenario Save Generate / Make / Run Barcode 12344

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-136 Referenced Sequence Diagrams Add the sequence diagram “Scenario generating a ticket”, to the use case “Generate a ticket showing total cost”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-137 Part Two Use Case 4 “Manage special offers”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-138 Special Offer Use case Open the Product Overview OMD and add a class entitled “ISpecialOffer” Add an aggregation from Product to ISpecialOffer Select the Interface stereotype for this class The > stereotype is just extra information informing the reader that this class is pure- virtual and must be sub-classed.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-139 Directed aggregation Change the relation to be directional and not symmetrical Change the role name to be itsSpecialOffer Set multiplicity 0..1

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-140 Abstract operation Add an operation getSpecialPrice() which returns an int that is “Virtual” and “Abstract” Add arguments unitPrice and quantity, both int’s

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-141 Special Offers Overview Add a new OMD entitled “Special Offers Overview” Set the main diagram for ISpecialOffer to this diagram

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-142 BuyOneGetOneFree Select the BuyOneGetOneFree class, right-click and select Implement Base Classes

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-143 Implement Base Classes We must implement the getSpecialPrice() operation, so tick the operation and select “Edit Code…” to enter the implementation.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-144 Using the special offer Modify the “ProductDatabase Overview” OMD Add the BuyOneGetOneFree class with a dependency from ProductDatabase to it. With the features for this dependency, set the stereotype to Usage. The > stereotype generates a #include “BuyOneGetOneFree.h”

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-145 Applying the special offer Modify the implementation of the ProductDatabase constructor

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-146 Product constructors Modify the Product constructors Set default value for aSpecialOffer to NULL

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-147 CountedProduct getPrice() Modify the implementation of the getPrice() operation of the CountedProduct class

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-148 generateTicket() Modify the generateTicket() operation of the CashRegister class

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-149 Figs are “buy one get one free!” Save / generate / make / run / go Send evS3 to the Cashier

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-150 Optimization : get / set We’ve implemented all our use cases and everything seems ok, it’s now time to do a little optimization Rhapsody generates by default a get and set for every attribute. We can tell Rhapsody not to generate these get / set operations and then generate them just when we need them. Set the following properties: Make sure that you select the properties for the entire project

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-151 Regenerating the code Select Code->Re Generate Make There will be errors, since we have used several accessors such as getBarcode()

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-152 Generating accessors Set the AccessorGenerate property to True for all the attributes in the Product and CountedProduct classes

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-153 Optimization : avoiding new We can also tell Rhapsody to not use ”new” when it creates instances of classes inside composite classes For example the Keyboard class currently creates an instance of the KeyReader class like this:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-154 Embedded classes Set the property CPP_CG:Class:Embeddable for the entire project and regenerate code Note that there is no longer a pointer to the KeyReader class and also that there is no longer a newItsKeyReader() operation

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-155 Correcting the errors Do a Make Correct the error in the Keyboard class by changing the -> to a.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-156 Embedded classes in the main Set the property CPP_CG:Configuration:InitializeEmbeddableObjects ByValue to True and regenerate code

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-157 Correcting the errors Do a Make Correct the errors in the main by changing the -> to. Note that new is no longer used.

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-158 Generating for another OS If we wanted to get this model to run on a target running an OS such as VxWorks, then all we need to do is copy the configuration, rename it and select the appropriate environment

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-159 Cross compiling We can generate and make this component

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-160 Running on the target 66K ROM Rhapsody Tasks

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-161 Generating a report Finally we can generate a report: For example an HTML documentation of just our use cases, actors and use case diagrams

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-162 Pre-defined report We can select a predefined report:

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-163 Final Report

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-164