Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001 Int-1 Section 3 Intermediate Inherited Sensor.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1.
Advertisements

Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
C++ Classes & Data Abstraction
Essential Rhapsody in C++
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.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 EI-1 “Essential” Rhapsody in C++ Introduction.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
© I-Logix Rhapsody C++ V /01/2004 E1-1 Exercise 2 : Count Down.
אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט1 פרק 8 נקודות חשובות בתרגילים 7-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 Modified.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Level Concurrency.
Advanced Object-Oriented Programming Features
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 13: Object-Oriented Programming
© 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.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Level Multiplicity.
Presentation 4: IBM Rational Software Architect Example James Martin CpE 691, Spring 2010 February 18, 2010.
Software Engineering 1 (Chap. 1) Object-Centered Design.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
A First Program Using C#
Programming Languages and Paradigms Object-Oriented Programming.
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 Architecture: Component and Deployment Diagrams Patrick Bailey Keith Vander Linden Calvin College.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
An Object-Oriented Approach to Programming Logic and Design
1 Understanding Inheritance COSC 156 C++ Programming Lecture 8.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Utilities (Part 2) Implementing static features 1.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level.
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
Prepared by: Elsy Torres Shajida Berry Siobhan Westby.
1 Chapter Nine Using GUI Objects and the Visual Studio IDE.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
C++ Programming Lecture 10 Functions – Part II
Eclipse. An IDE is an Integrated Development Environment Different IDEs meet different needs BlueJ, DrJava are designed as teaching tools Emphasis is.
Order of Constructor Call. Base class constructors are always called in the derived class constructors. Whenever you create derived class object, first.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
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.
Object Oriented Software Development 4. C# data types, objects and references.
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.
© I-Logix Rhapsody C++ V /01/2004E1-1 “Essential” Tool Training Basic Rhapsody Basic Rhapsody Rhapsody in C++ V /01/04.
1 Introduction to Object Oriented Programming Chapter 10.
Programming Fundamentals Enumerations and Functions.
CHAPTER 4 FUNCTIONS Dr. Shady Yehia Elmashad. Outline 1.Introduction 2.Program Components in C++ 3.Math Library Functions 4.Functions 5.Function Definitions.
Rhapsody 2003년 3월 12일 배대호.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Chapter 14 Windows Programming with the Microsoft Foundation Classes
Modern Programming Tools And Techniques-I
SAP Business One B1iF Training
Review: Two Programming Paradigms
Inheritance in Java.
Using GUI Objects and the Visual Studio IDE
PRG 218 Week 5 Individual Assignment Coding: Derived Classes Please click here to buy ( (
Understanding Inheritance
Lecture 22 Inheritance Richard Gesick.
CIS 199 Final Review.
Java Programming with BlueJ Objectives
Essential Rhapsody in C++
C++ Object Oriented 1.
Presentation transcript:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-1 Section 3 Intermediate Inherited Sensor

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-2 Inherited Sensor Create a new project called “Inheritance” in C:\Rhapsody\Work\Inheritance Draw two classes Motor and Sensor Draw two classes TemperatureSensor and PressureSensor

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-3 Inheritance Make the PressureSensor and TemperatureSensor inherit from the base class Sensor. Add directed associations from the Motor to the PressureSensor and to the TemperatureSensor. Set the multiplicity to 1.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-4 Base Class Sensor Add attribute name of type OMString Add a constructor that receives an argument aName of type OMString Initialize the attribute in the initializer name(aName) Create an operation print with implementation std::cout << name << “ “;

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-5 Motor Class Create a constructor that creates instances of both types of Sensor: setItsTemperatureSensor(new TemperatureSensor(“T1”)); setItsPressureSensor(new PressureSensor(“P1”));

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-6 Derived Sensor Classes For both derived Sensor classes: Create a constructor that has an argument aName of type OMString Set the Initializer to Sensor(aName) Sensor(aName) invokes the Sensor constructor so as to initialize the name field of the base class.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-7 Animating Create a Test component and a Debug configuration that creates an initial instance of the Motor class Save / Generate / Make / Run With the browser, note that there are two instances of Sensor. Each Sensor has a name that has been initialized.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-8 Section 3 Intermediate Virtual Operations

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-9 Virtual Operations Save the “Inheritance” project as new project “Virtual” in C:\Rhapsody\Work\Virtual Add a directed association, multiplicity 1 from the Motor to the Sensor Create a virtual operation read() in the base class Sensor Make an operation virtual by checking the virtual box in the features.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-10 Overloaded Operations In the TemperatureSensor add an operation read() with implementation: std::out << “Temperature = “ << rand() % 100 << “ deg F” << std::endl ; In the PressureSensor add an operation read() with implementation : std::cout << “Pressure = “ << rand() % 10 << “ bars” << std::endl; A quick way of creating these read operations is to hold the control key down and drag the read operation from the Sensor class to the TemperatureSensor. This will make a copy.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-11 Motor Constructor Change the implementation to:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-12 Output Save / Generate / Make / Run Show that there are two instances of Sensor Show the output is as follows: Note that itsSensor->read() calls the read operation for the TemperatureSensor rather than the read operation of the Sensor class.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-13 Sequence Diagram Create a sequence diagram named “Creation” with a system border and add instances of Motor, PressureSensor and TemperatureSensor. Save / Generate / Make / Run A quick way of constructing the instances on a sequence diagram is to drag the classes from the browser.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-14 Animated Sequence Diagram Read operations are executed from the motor constructor Instances created by dragging classes from browser to sequence diagram This is not exactly what we would have expected. We can see that the read operations come from the system border rather than from the Motor. Until an object is fully constructed, all messages will be shown as coming from the system border.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-15 User Types Using the browser, right-click on the Default package and select “Add New Type” add a type tTempUnits declared as –enum tTempUnits { CELSIUS, FAHRENHEIT }; An alternative declaration is : enum %s { CELSIUS, FAHRENHEIT }.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-16 Attribute Unit Add an attribute unit of type tTempUnits for the TemperatureSensor. Add an argument to the TemperatureSensor constructor called aUnit of the same type In the initializer add,unit(aUnit)

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-17 TemperatureSensor Change the read operation to : cout << “Temperature = “ << rand() % 100 << “deg “; if ( unit == CELSIUS ) std::cout << “C” << std::endl; else std::cout << “F” << std::endl; In the Motor constructor, add the argument “CELSIUS” as follows: setItsTemperatureSensor (new TemperatureSensor( “T1”, CELSIUS));

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-18 Output Save / Generate / Make / Run Output should be similar to previous, except that temperatures are in Celsius.