ITEC 320 Lecture 23 OO in Ada. OO in Ada(1) Review Questions? Exam 2 next Friday ADTs.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

A little bit on Class-Based OO Languages CS153: Compilers Greg Morrisett.
Slide: 1 Copyright © AdaCore Record Types Presented by Quentin Ochem university.adacore.com.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
ITEC 320 Lecture 12 Records. Intro to records Review Look_ahead(char,EOL); –What is this? –What does it allow us to do?
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
ITEC 320 Lecture 11 Pointers(1). Pointers Review Packages –Generic –Child Homework 3 is posted.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
ITEC 320 Lecture 24 OO in Ada (2). Review Questions? Inheritance in Ada.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Object Oriented Programming and Object Oriented Design Programming Languages Robert Dewar.
Array Types Index types can be of any discrete type Component type must be definite, i.e. have bounds: type class_list is array ( ) of String (1..10);
CIS 101: Computer Programming and Problem Solving Lecture10 Usman Roshan Department of Computer Science NJIT.
G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.
2 Objectives You should be able to describe: Operator Functions Two Useful Alternatives – operator() and operator[] Data Type Conversions Class Inheritance.
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
ITEC 320 Lecture 16 Packages (1). Review Questions? –HW –Exam Nested records –Benefits –Downsides.
EECE 310: Software Engineering Lecture 2: Understanding Objects in Java and Types.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Porting Implementation of Packet Utilization Standard from ADA to JAVA Annelie Hultman (TEC-EME) Donata Pedrazzani (TEC-EMS) ESA/ESTEC 2004 JPUS de-briefing.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
ITEC 320 Lecture 13 OO in Ada. OO in Ada(1) Review Questions? HW 3 due tomorrow night.
ITEC 320 Lecture 10 Packages (2). Review Packages –What parts do they have? –Syntax?
Slide: 1 Copyright © AdaCore Subprograms Presented by Quentin Ochem university.adacore.com.
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Prepared by: Elsy Torres Shajida Berry Siobhan Westby.
Types in programming languages1 What are types, and why do we need them?
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
1 © AdaCore under the GNU Free Documentation License Franco Gasperoni
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Transition to Java Programming with Alice and Java First Edition.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Stephen Davis Ada Object-Oriented Programming. Overview Ada 83 is not considered a true “object-oriented” programming language. Although Ada 83 did support.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Data Types Chapter 6: Data Types Lectures # 12. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
ISBN Chapter 12 Support for Object-Oriented Programming.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Records type city is record -- Ada Name: String (1..10); Country : String (1..20); Population: integer; Capital : Boolean; end record; struct city { --
Advanced Data Structures Lecture 1
Data Types In Text: Chapter 6.
Object-oriented Programming in Java
Semantic Analysis Type Checking
Andy Wang Object Oriented Programming in C++ COP 3330
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CS230 Tutorial Week 3.
Types of Programming Languages
Compiler Design 18. Object Oriented Semantic Analysis (Symbol Tables, Type Checking) Kanat Bolazar March 30, 2010.
Explicit and Implicit Type Changes
Java Programming Language
Support for Object-Oriented Programming in Ada 95
Chapter 6 Intermediate-Code Generation
Introduction to Data Structure
Java Programming Language
design OO words Debug Variables Data types
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

ITEC 320 Lecture 23 OO in Ada

OO in Ada(1) Review Questions? Exam 2 next Friday ADTs

OO in Ada(1) Objectives Define OO Look at Ada components Records

OO in Ada(1) O_O What do you consider object oriented programming? What language features are necessary? What are the benefits / downsides of it? Examples?

OO in Ada(1) Variant records Unions in C/C++ One data structure, choose one of the following variables Example: Payment types –Cash –Check –Credit

OO in Ada(1) Example type PaymentType is (Cash, Check, Credit); -- The_Type is called the discriminant of the type type Transaction(The_Type: PaymentType := Cash) is record Amount: Integer; case The_Type is when Cash => Discount: boolean; when Check => CheckNumber: Positive; when Credit => CardNumber: String(1..5); Expiration: String(1..5); end case; end record;

OO in Ada(1) Usage t: Transaction; -- Default is cash transaction begin -- All transactions have an amount field put(t.amount); -- Cash transactions have a discount field if t.discount then put("Give a discount"); else put("No discount"); end if; -- Create a new credit transaction t := (credit, 100, "12345", "01/05"); t.amount := 200; put(t.amount); put(t.CardNumber); put(t.Expiration); put(t.CheckNumber); -- Compiles but raises constraint error --t.The_Type := check; -- Compile error. --When changing discriminant, the entire record must be assigned.

OO in Ada(1) Uses Stacks –Keep track of all possible transactions –Accounting Types that have common characteristics –What feature in OO is this like?

OO in Ada(1) Memory Consider What does this say about memory? t := (cash, false); t := (credit, 100, "12345", "01/05"); t := (check, 1234);

OO in Ada(1) Dangers Consider t := (credit, 100, "12345", "01/05"); if t.discount... end if; t := (cash, false); put(t.CheckNumber);

OO in Ada(1) Safety Compile time –Type must defined when record created –When type is changed, entire record must be reassigned Run time –Checking to see if type  field usage

OO in Ada(1) Other languages Figure out how much memory is needed union mytypes_t { int i; float f; char c; } mytypes; // These all share the same memory location: mytypes.i; mytypes.f; mytypes.c ;

OO in Ada(1) Issues Still not extendable No way to create a subtype that allows access to parent’s values the same way it’s values can be accessed More of a here is an interesting variation on a particular feature

OO in Ada(1) True OO Tagging – Let Ada know you will be changing it type Object is tagged record X_Coord: Float; Y_Coord: Float; end record; type Point is new Object with null record; type Circle is new Object with record Radius: Float; end record;

OO in Ada(1) Usage Creation O: Object := (1.0,.5); C: Circle := (0.0, 0.0, 34.7); type Cylinder is new Circle with record Height: Float; end record; Cyl: Cylinder; Cyl := (O with Radius =>41.2, Height =>231.6); Cyl := (C with Height => 231.6);

OO in Ada(1) Points Existing components are inherited Once you derive, the parent type cannot be changed, only the child type Can be converted to an ancestor type, not vice versa (unless untagged)

OO in Ada(1) Designs Create a base type Have all your procedures / functions use the base type Clients can create new types and send the new type cast as an ancestor to the package Packages can have multiple functions with multiple parameter types (one for each derived / original type)

OO in Ada(1) Pointers Create a “generic type” that is just a place holder Derive all of your types from it Make your data structures work with the “generic type” –One linked list w/ multiple types stored No need for generics with this method

OO in Ada(1) Next time Continuing on with OO programming in Ada –Abstract

OO in Ada(1) Summary Variant Records