Abstract Types Defined as Classes of Variables Jeffrey Smith, Vincent Fumo, Richard Bruno.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Encapsulation by Subprograms and Type Definitions
Introduction and a Review of Basic Concepts
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
C++ fundamentals.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
PROGRAMMING LANGUAGES The Study of Programming Languages.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Chapter 3 Introduction to Collections – Stacks Modified
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction Structures are somewhat like an array in that.
Values, variables and types © Allan C. Milne v
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
CHAPTER 3 Function Overloading. 2 Introduction The polymorphism refers to ‘one name having many forms’ ‘different behaviour of an instance depending upon.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Learners Support Publications Classes and Objects.
Ch. 5 Ch. 51 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
1 CSC241: Object Oriented Programming Lecture No 25.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
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.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Classes, Interfaces and Packages
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
1 Chapter 9 Introduction to Classes and Objects Program Development and Design Using C++, Third Edition.
Java Programming Language Lecture27- An Introduction.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Algorithms and Problem Solving
User-Written Functions
Introduction to the C Language
Introduction to the C Language
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Classes and Objects.
Algorithms and Problem Solving
Introduction to Data Structure
Review: libraries and packages
Abstract Types Defined as Classes of Variables
Presentation transcript:

Abstract Types Defined as Classes of Variables Jeffrey Smith, Vincent Fumo, Richard Bruno

Introduction What is a type Current approaches Why a new definition The new approach Common Types Questions

What is a Type? Primitive types implicitly defined by types supported by the language used. User-defined types allow user to add new types without altering the compiler thereby removing the implicit definition of type. Formal definition of type necessary given the proliferation of user-defined types.

Syntactic Approach This approach provides the typing information in the variable declaration. Example – Visual Basic Dim Index as Integer Example – C++ Int index,counter;

Value Space Approach This approach uses the idea of enumeration. Here is a list of possible values that implicitly define the type. Example – Type will hold Boolean information thus it will contain T or F, 1 or 0, etc.

Behavior Approach This builds on value space by adding the notion of a set of operations to the space. Example from C: Boolean flag; void setTrue() { flag = 1; } void setFalse() { flag = 0; }

Representation Approach Here the type is shown in terms of its primitive types. The primitives are usually hardware or compiler implemented. Example – C style structure: struct address { char *street; char *street2; char *city; char *state; double zip; };

Representation and Behavior Approach Type defined by a representation combined with a set of operator defining its behavior. Example – A Class in C++ Class Time { public: Time(); void setTime(int, int, int); void PrintStandard(); private: int hour; int minutes; int second; };

Why Don’t These Work? The previously outlined approaches don’t define extensible language types because: Can’t create clear and simple semantic rules Can’t achieve practical goals (strong compiler type checking)

Why Type Extension? Type extension needs to support the following four goals: Abstraction Redundancy and compile time checking Abbreviation Data Portability

Abstraction We abstract to generalize problems in hopes of solving many problems at once (in terms of the abstraction). User-defined data types are usually abstractions of more primitive structures and data types. Abstraction lends itself well to: Structured programming Stepwise refinement Information hiding

Redundancy / Compile Time Checking User-defined type provides more information about data stored than primitive types do. Restricting the possible set of operations on the data. Example from C: void main (void) { int a; char b ='a'; char c ='b'; a = b + c; }

Abbreviation User-defined data types make for shorter programs that are easier to understand, modify, write, etc. Example: desired: Function do_something(recordset); Undesired: Function do_something(int1, int2, char, string, int, char);

Data Portability User-defined data types reduce the changes necessary when new data or data organization is introduced. The abstraction present in the user- defined data type aids in making your design language independent. Example – XML – Abstract the data into XML. Describe the data in XSL.

Goals Not Realized? Current languages (1975) have not reached the stated goals. Five “original” definitions (syntactic, behavior, etc.) of types are too restrictive to allow the new goals (abstraction, abbreviation, etc.) outlined to be achieved.

Mode of a Variable A mode is a group of variables that are represented and accessed in the same manner. Defines an equivalence class on variables. (ie. Any value that can be stored in a particular mode can be stored in any mode of that type).

Classes of Modes Two modes are in the same class (of the same type) if they can be substituted without generating a compile-time error. Classes of modes are Types. Types which contain more than one mode are abstract data types.

Int x; Char y; Void Function1(int x); Type 1 Int a; Char b; Void Function1(int a); Type 2 Example Here Type 1 and Type 2 are in the same class because their operations and variables are the same. In other words, they are of the same mode.

Hierarchical Structure? Types are classes of modes. Modes are classes of variables. A hierarchical relationship exists with the relation being “are classes of” Types Modes Variables

Spec-Types These are types that are defined by the characteristics observed using the operators. Their internal representation does not matter, so long as they meet the specification.

Spec-Type Example Double x Double y Int Op1(); //Add values Void Op2(); //Multiply values Spec-Type B Int x Int y Int Op1(); //Add values Void Op2(); //Multiply values Spec-Type A Type A and Type B are spec-types because you can put the same inputs into either one and you will get the same result…..thus they meet the specification. Note: Identically named functions implies identical operations.

Rep-Type These types are defined by their internal representations. Those types with identical internal representations are of the same rep- type but may not have the same characteristics when the operators are applied to the representation.

Rep-Type Example double x double y Compute () { (x*y)*x); } Type Complex double realpart; double complexpart; Compute () { (x*y)*x; } Type Cartesian Type A and Type B are rep-types because both types have the same internal representation.

Param-Type The operations and variables are the same but underlying representations between two types are not the same. C++ Templates or Java Interfaces easily demonstrate this concept.

Param-Type Example Template Class QUEUE { Public: enum{MAXENTRIES=128}; protected: My_type* array; int Max, Begin, End, OverWriteFlag, LastItemFlag void IntArray(); void CleanupArray(); public: QUEUE(); QUEUE(int num); ~QUEUE(); void Push(my_type* obj); my_type* Pop(void); void Clear (void); }; This class will work for any type fed into the function. Without the use of the template, you would have to create a separate class for each type Queue we need.

Variant Types These are types that have common properties but are not exact specifications. A weaker form of Spec-Types

Variant-Types Example Double x Double y Void Op1(); //Add values Type B Int x Int y Void Op1(); //Add values Int Op2(); //Multiply values Type A Type B and type A are variant-types since type B shares Op1 with type A. Type B however, adds a second operation Op2.

More About Types The types listed (spec, rep, param and variant types) are not an exhaustive set of types, just the most common ones. The authors essentially describe a C++ class – classes contain data representation and operations. He even calls them Classes!

Code Sharing? In order to share code the compiled code must be able to anticipate all spec- types that can occur. Example – You must consider things like big-endian and little-endian (ie. Whether least or most significant bits are stored first).

The bottom line…..

Go Invent C++