Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001 Adv-1 Section 4 Advanced Level Multiplicity.

Slides:



Advertisements
Similar presentations
Essential Rhapsody in C++
Advertisements

Rhapsody in C++ Tool Training "Essential" © I-Logix v4.1 01/01/2003 E2-1 Essential Rhapsody in C++ Part Two Case Study.
Exceptions, Templates, And The Standard Template Library (STL) Chapter 16.
Copyright © 2012 Pearson Education, Inc. Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)
Stack and Queue Dr. Bernard Chen Ph.D. University of Central Arkansas.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Bas-1 Essential Rhapsody in C++ Section 2 Basic Level.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Mutexes.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Chapter 10.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 EI-1 “Essential” Rhapsody in C++ Introduction.
© 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.
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
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.
OOP Project Develop an Application which incorporates the following OO Mechanisms and Principals: – Classes Visibility Constructor(s) Class Variable (if.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-1 Section 3 Intermediate Inherited Sensor.
Discussion 2: PA1 Siarhei Vishniakou CSE 100 Summer 2014.
© I-Logix Rhapsody C++ V /01/2004 E1-1 Exercise 3 : Dishwasher.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Int-1 Essential Rhapsody in C++ Section 3 Intermediate Level.
C++ fundamentals.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
OOP Languages: Java vs C++
A First Program Using C#
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Programming Languages and Paradigms Object-Oriented Programming.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Java and C++, The Difference An introduction Unit - 00.
1 I-Logix Professional Services Specialist Rhapsody IDF (Interrupt Driven Framework) CPU External Code RTOS OXF Framework Rhapsody Generated.
Implementation Yaodong Bi. Introduction to Implementation Purposes of Implementation – Plan the system integrations required in each iteration – Distribute.
CS352-Week 2. Topics Heap allocation References Pointers.
Spreadsheets in Finance and Forecasting Presentation 9 Macros.
Polymorphism Lecture-10. Print A Cheque A Report A Photograph PrintCheque() PrintReport() PrintPhoto() Printing.
Chapter 10 Fireworks: Part II The Web Warrior Guide to Web Design Technologies.
Creating your first C++ program
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 9: Interaction.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Active-HDL Interfaces Building VHPI Applications C Compilation Course 9.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level.
Rhapsody V4.2 "Specialist" Tool Training © I-Logix /08/20031 Specialist Rhapsody Getting Rhapsody In C generated code to run.
Chapter 10 Making Books, Tables of Content, and Indexes.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
Using COMET with Visio Visio UML Modeling. Creating a Drawing After opening Visio, you will see a list of templates available.
Iterator for linked-list traversal, Template & STL COMP171 Fall 2005.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
1 Chapter 1 C++ Templates Sections 1.6 and Templates Type-independent patterns that can work with multiple data types –Generic programming –Code.
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.
Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
© I-Logix Rhapsody C++ V /01/2004E1-1 “Essential” Tool Training Basic Rhapsody Basic Rhapsody Rhapsody in C++ V /01/04.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
IBM Rational Rhapsody Advanced Systems Training v7.5
Customizing custom.
IBM Rational Rhapsody Advanced Systems Training v7.5
Dr. Bernard Chen Ph.D. University of Central Arkansas
Review: Two Programming Paradigms
Object-Orientated Programming
PRG 218 Week 5 Individual Assignment Coding: Derived Classes Please click here to buy ( (
Array Lists Chapter 6 Section 6.1 to 6.3
Java Programming with BlueJ Objectives
Essential Rhapsody in C++
Presentation transcript:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Level Multiplicity

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-2 Containers A container is a collection of objects. Rhapsody uses containers for managing all “1 to many” and “many to many” relations. The containers are implemented using template classes. The Rhapsody containers are called OMContainers. Rhapsody also provides containers called OMUContainers that don’t use templates.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-3 Relations The following table shows how Rhapsody implements relations:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-4 OMCollection

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-5 OMList

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-6 OMMap

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-7 Iterators An iterator is a friend class to a container, that is used to keep a pointer to the current element in the container. Iterators are needed so that many classes can have concurrent access to the same container.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-8 Using OMIterator Rhapsody provides an OMIterator class that can be used as follows to iterate through a container: OMCollection itsSensor; // a container OMIterator iSensor(itsSensor); iSensor.reset(); // point to first while ( *iSensor != NULL ) { (*iSensor)->print();// print ++iSensor;// point to next }

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-9 Other Libraries Other libraries can be used instead of OMContainers and OMString, such as : –STL (Standard Template Library) ( See the appropriate Specialist section for more information ). –Rhapsody OMUContainers ( This is a container set similar to OMContainers except that templates are not used, this can help reduce code size ). It is also possible to add your own container set or integrate a third party container set such as the RogueWave libraries.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-10 Using OMUContainers To use the Rhapsody containers that don’t use templates, select the OMUContainers:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-11 Using OMUIterator Rhapsody provides an OMUIterator class that can be used as follows to iterate through a container: OMUCollection itsSensor; // a container OMUIterator iSensor(itsSensor); iSensor.reset(); // point to first while ( *iSensor != NULL ) { (static_cast (*iSensor))->print(); ++iSensor; // point to next } Note the static_cast to convert from void* to Sensor*

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-12 Section 4 Advanced Level Collection

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-13 Collection of Sensors Load the “Virtual” project and save as “Collection” Delete from Model the relations between the Motor and the Sensors. Check in the Browser that these relations have been deleted from the model not just the view. Add a directed aggregation itsSensor from the Motor to the Sensor. Set Multiplicity to * (many).

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-14 OMCollection Delete implementation of Motor constructor Save / Generate / Examine code for Motor Note that the relation has been implemented as a collection of Sensors: OMCollection itsSensor; Note also that there is an operation addItsSensor(Sensor* p_Sensor);

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-15 Adding to OMCollection In the motor constructor add Sensors: –addItsSensor(new TemperatureSensor(“Sensor1”,CELSIUS)); –addItsSensor(new TemperatureSensor(“Sensor2”,FAHRENHEIT)); –addItsSensor(new PressureSensor(“Sensor3”) );

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-16 Dependencies In order to compile, the Motor needs to include the Pressure and Temperature Sensors header files. To do this we will add dependencies from the Motor to those classes: Double-click on each dependency and select the stereotype Usage.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-17 Implementation Includes Alternatively instead of drawing dependencies, we can just modify the properties for the Motor class and for CPP_CG->Class->ImpIncludes add TemperatureSensor.h,PressureSensor.h CPP_CG means C++ Code Generation.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-18 Multiple Relation Save / Generate / Make / Run Show that the Motor has a collection of three Sensors.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-19 Statechart Create a simple Statechart for the Motor class that calls a pollSensors() routine every two seconds.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-20 pollSensors() Create the pollSensors() operation that will poll all the Sensors in the collection: Note that if any more Sensors of any other type are added, the operation still functions! OMIterator iSensor(itsSensor); for ( iSensor.reset(); *iSensor; ++iSensor ) { (*iSensor)->print(); (*iSensor)->read(); } cout << " " << endl;

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-21 Output Save / Generate / Make / Run Verify the output The syntax for an iterator is a little complex, but it’s used in the same way every time.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-22 Sequence Diagram Create a sequence diagram entitled “What we expect” as shown in the next slide. Create the instances by dragging the classes onto the sequence diagram from the browser. Right click on each TemperatureSensor line to bring up the features where the instance name can be entered. Note that an other way is to drag instances rather than classes onto the sequence diagram. Now that we have several instances of a class, on a sequence diagram we have to indicate the instance name and not just the class.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-23 Another way is to drag instances from the browser during animation. (Drag the instances from TemperatureSensor and the PressureSensor classes not the Sensor class). Sequence Diagram

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-24 Animated Sequence Diagram Save / Generate / Make / Run. Animate and check that what we expect is what we get. When executing the code, then only if a SD is open, will an animated SD will be created.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-25 When executing the code, then only if a SD is open, will an animated SD will be created. Comparing Sequence Diagrams Use “Tools>Sequence Diagram Compare” to examine the differences between “What we expect” and “Animated What we expect”

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-26 Note the differences are highlighted in Magenta. The Comparison

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-27 Interpreting the Comparison As we can see the result is not as we expected, (the order of constructing the instances is different). This is because, Rhapsody does not consider an object to exist until it’s constructor has terminated, this is why all the constructors come from the system border.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-28 Using the Comparison Options We can set an option so that the constructors are not compared.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-29 Using the Comparison Options We can set an option so that the constructors are not compared.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-30 The Modified Comparison Note the differences are now grayed out.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-31 Extended Exercise For the Sensor class, add a static attribute numberOfSensors of type int with initial value 0. In the Sensor Constructor add numberOfSensors++; For the Sensor class, add a virtual Destructor with implementation : numberOfSensors--; Add the following to pollSensors() cout << “Number of sensors = “ << Sensor::getNumberOfSensors() << endl; Generate code and execute to check that numberOfSensors = 3.