Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.

Slides:



Advertisements
Similar presentations
MT311 (Oct 2007) Java Application Development Object-Oriented Programming Languages Tutorial 8.
Advertisements

Programming Languages and Paradigms
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
CPS 506 Comparative Programming Languages Abstract Data Type and Encapsulation.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
1) More on parameter passing: a) Parameter association b) Default parameters c) Procedures as parameters 2) Modules: Ada packages, C modules, C header.
Abstract data types & object-oriented paradigm. Abstraction Abstraction: a view of an entity that includes only the attributes of significance in a particular.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
C++ fundamentals.
 By Wayne Cheng.  Introduction  Five Tenets  Terminology  The foundation of C++: Classes.
Object Oriented Programming
Chapter 11 Abstract Data Types and Encapsulation Concepts.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Software Development. Software Developers Refresher A person or organization that designs software and writes the programs. Software development is the.
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
1 Abstract Data Types & Object Orientation Abstract Data Types (ADT) Concepts –Data Abstraction –ADT in PLs –Encapsulation Object Orientation –Principal.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Data Abstaraction Chapter 10.
Abstraction ADTs, Information Hiding and Encapsulation.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Object-Oriented Programming Chapter Chapter
ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
ISBN Object-Oriented Programming Chapter Chapter
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
9 장 추상 데이터 타입 및 모듈 (Abstract Data Type & Module).
Chapter 11 Abstract Data Types and Encapsulation Concepts.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
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.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Principles of programming languages 10: Object oriented languages
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Abstract Data Types and Encapsulation Concepts
ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:
11.1 The Concept of Abstraction
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Abstract Data Types Objects are one way to implement ADTs
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Stack ADT & Modularity 2 implementations of the Stack abstract data type: Array Linked List Program design: modularity, abstraction and information hiding.
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Programming Languages and Paradigms
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information hiding  reliability  security  reuse

Chapter 10, Slide 2 ADT PROPERTIES Defines a collection of objects, and a Set of applicable operations Representation of objects is hidden Operations by outsiders is restricted to only those operations that are visible

Chapter 10, Slide 3 COMMON FORMAT OF DESCRIPTION SPECIFICATION  Defines type name and parameters  Names visible operations and results types BODY  Describes syntax of type objects  Describes visible and hidden operations

Chapter 10, Slide 4 IMPLEMENTATIONS SIMULA 67 - first to introduce classes, retrospectively recognized to be ADTs CLU - an experimental language that introduced ADTs Modula-2 - first generally accessible implementations in a wdiely used language Smalltalk - used ADTs as basis for objects Ada - used ADTs in packages C++ - added ADTs to C

Chapter 10, Slide 5 ENCAPSULATION and INSTANTIATION ENCAPSULATION  the syntax of the specification as a separate module  builds a “fire-wall” around the type  provides a reusable, portable object  the development of the idea of a type as an object INSTANTIATION  the creation of an instance of the type  the operation of importing an ADT into another program unit  may include initialization actions  scope may be limited to the lifetime of the user module or may be specified

Chapter 10, Slide 6 Abstract Data Types - details Type representation and operations on that type are defined together. Representation is hidden from user of the type -- objects of type t can only be manipulated by operations defined for t. Advantages of user-defined ADTs  encapsulation  protection  extensibility We’ll look at three languages:  Simula 67  Ada  Modula-2

Chapter 10, Slide 7 Simula 67: Classes A class consists of:  variable declarations  procedure declarations  code (for initialization) If C is a class with variables x 1...x n and procedures p 1...p k, an instance of C is a dynamically created object, say r. ref (C) r;... r :- new C;......r.x i......r. p j (y 1... y m )...

Chapter 10, Slide 8 Stack Example initialization code class stack; begin integer array a( ); integer top; boolean procedure empty;... end; procedure push (element);... end; procedure pop;... end; procedure look;... end; top := 0; end stack;

Chapter 10, Slide 9 Using the Stack Class allowed, but unsafe. ref (stack) s1,s2;... s1 :- new stack; s2 :- new stack; s1.pop; -- error s1.push(5);... s1.look; s2.look ; -- error...  But no protection! s2.a(4) := 1000; s1.top := 0;

Chapter 10, Slide 10 Inheritance in Simula If x is a subclass of y, then instances of x have all of x's attributes plus all of y's attributes.  x inherits the attributes of y. Example: defining a heterogeneous stack class stack_mem begin ref(stack_mem) next_mem next_mem :- none end stack_mem;

Chapter 10, Slide 11 Example Continued: Define stack class stack; begin ref (stack_mem) first; ref (stack_mem) procedure top top :- first; procedure pop; if not(empty) then first :- first.next_mem; boolean procedure empty; empty :- (first = = none); procedure push(e); ref(stack_mem) e; begin if first =/= none then e.next_mem :- first; first :- e; end first :- none; end stack;

Chapter 10, Slide 12 Example Continued: Stackable Objects Stackable objects must be instances of a subclass of stack_mem: stack_mem class complex(...) -- declare complex as subclass of stack_mem... end complex Another example: class mammal; mammal class dog; mammal class cat; dog class golden_retriever;

Chapter 10, Slide 13 Packages in Ada Two parts:  specification: provides interface, defines visibility.  body: provides implementation Important:  Support separate compilation so that if package p1 uses package p2, p1 can be compiled given only the specification part of p2.

Chapter 10, Slide 14 Package Example package stack is-- the specification type stacktype; function empty (s: in stacktype) return boolean; procedure push (e: in integer; s: in out stacktype); procedure pop (s: in out stacktype); function top(s: in stacktype) return integer; end stack; package body stack is-- the body type stacktype is... function empty (...) is......

Chapter 10, Slide 15 Package example (continued) Does our separate compilation rule hold:  No!  Definition for stacktype must be in the interface too. Problem: We didn't want stacktype's definition to be exported.  Solution: Divide the specification into a public part and a private part.

Chapter 10, Slide 16 New Specification for stack package stack is-- the visible part type stacktype is private; function empty(...)... procedure push private-- the private part type list_type is array (1..100) of int; type stacktype is record list : list_type; top : integer range := 0 end record; end stack;

Chapter 10, Slide 17 Using Packages with stack; procedure p is s : stack.stacktype; begin... stack.push(4,s);...stack.top(s)...;... end OR... with stack; use stack; procedure p is s : stacktype; begin... push(4,s);...top(s)...;... end

Chapter 10, Slide 18 Ada Generic -- Abstract Package generic -- A private generic type means assignment and equality must be -- defined on that type type Elem is private ; package List is type T is private ; -- Create operation is implicit. Lists created by declaration procedure Head (L: T ; V: out Elem ; Err: out ERROR_INDICATOR) ; -- Length can’t fail so no need for error indicator function Length (L: T) return NATURAL ; procedure Tail (L: T ; LT: out T; Err: out ERROR_INDICATOR ) ; -- Cons can’t fail so no need for error indicator function Cons (L: T ; V: Elem ) return T ; private -- an Ada access type corresponds to a Pascal pointer -- the entity referenced by the pointer is defined in the package body -- In this case, it would be a record with one field pointing to the next -- list element type LISTREC ; type T is access LISTREC ; end List ;

Chapter 10, Slide 19 Modules in Modula-2 Very similar to Ada packages, but only pointer types can be exported. Definition module stack;-- public type stacktype; procedure empty end stack; Implementation module stack;-- private type stacktype = pointer to record list :... topsub:...

Chapter 10, Slide 20 Modula-2 Modules (continued) What are the repercussions of this design decision?  separate compilation is easy (+)  module must supply a creation/initialization routine (-)  extra use of pointers (-)