+ All Categories
Home > Documents > Abstract Types Defined as Classes of Variables Jeffrey Smith, Vincent Fumo, Richard Bruno.

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

Date post: 16-Jan-2016
Category:
Upload: meredith-thomas
View: 223 times
Download: 0 times
Share this document with a friend
31
Abstract Types Defined as Classes of Variables Jeffrey Smith, Vincent Fumo, Richard Bruno
Transcript
Page 1: Abstract Types Defined as Classes of Variables Jeffrey Smith, Vincent Fumo, Richard Bruno.

Abstract Types Defined as Classes of Variables

Jeffrey Smith, Vincent Fumo, Richard Bruno

Page 2: 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

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

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.

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

Syntactic Approach

This approach provides the typing information in the variable declaration.

Example – Visual BasicDim Index as Integer

Example – C++Int index,counter;

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

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.

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

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;}

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

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;

};

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

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;

};

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

Why Don’t These Work?

The previously outlined approaches don’t define extensible language types because:Can’t create clear and simple semantic

rulesCan’t achieve practical goals (strong

compiler type checking)

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

Why Type Extension?

Type extension needs to support the following four goals:AbstractionRedundancy and compile time checkingAbbreviationData Portability

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

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

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

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;}

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

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);

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

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.

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

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.

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

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).

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

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.

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

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.

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

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

1

2

3

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

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.

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

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.

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

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.

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

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.

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

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.

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

Param-Type ExampleTemplate <class my_type>

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.

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

Variant Types

These are types that have common properties but are not exact specifications.

A weaker form of Spec-Types

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

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.

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

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!

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

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).

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

The bottom line…..

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

Go Invent C++


Recommended