(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)

Slides:



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

Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
ICE1341 Programming Languages Spring 2005 Lecture #18 Lecture #18 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
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.
CS2403 Programming Languages Abstract Data Types and Encapsulation Concepts Chung-Ta King Department of Computer Science National Tsing Hua University.
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.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
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
© 2006 Pearson Addison-Wesley. All rights reserved 4-1 Chapter 4 Data Abstraction: The Walls.
Abstract Data Types and Encapsulation Concepts
OOP Languages: Java vs C++
Chapter 11 Abstract Data Types and Encapsulation Concepts.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
1 Chapter 11 Abstract Data Types and Encapsulation Constructs.
Chapter 11 and 12: Abstract Data Types and Encapsulation Constructs; Support for Object Orientation Lesson 11.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Introduction to Object Oriented Programming CMSC 331.
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
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.
Data Abstaraction Chapter 10.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Views of Data Data – nouns of programming world the objects that are manipulated information that is processed Humans like to group information Classes,
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.
ISBN Object-Oriented Programming Chapter Chapter
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
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 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.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Chapter 11 Abstract Data Types and Encapsulation Concepts.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Abstract Data Types and Encapsulation Concepts
Data Abstraction: The Walls
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
Abstract Data Types Objects are one way to implement ADTs
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
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.
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Data Abstraction: The Walls
Abstract Data Types and Encapsulation Concepts
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)

(2) Abstraction In general: A view or representation of an entity that includes only the attributes of significance in a particular context In computer science: Separation of specification from implementation A weapon against the complexity of programming

(3) Information Hiding Why hide information from yourself and other programmers? “You don’t want to know” But also … “If I told you I’d have to kill you!” Not quite, but … “A little knowledge is a dangerous thing”

(4) Types of Abstraction Process Abstraction Saying that a process will be done without saying how As old as the first programming languages: functions and subprograms Data Abstraction Saying that data has certain properties without saying how it is represented Properties are specified in terms of operations, which are process abstractions

(5) Encapsulation Motivations: Large programs hard to understand without modularization Cost of recompilation becomes high Encapsulation into Modules solves both these problems Syntactic units that group together data and the operations that apply to them When done right, modules - are compilation units and - provide an abstract logical organization

(6) More on Modules Information Hiding is key to abstraction Small modules easier to Write Test Understand Maintain Reuse Small change in specification should mean small change in implementation

(7) Evolution of Encapsulation LISP Functions provide procedural abstraction No particular organization ALGOL Organization by nested subprograms Not independent of each other C Separately compiled files Type checking across files not done Modern languages Modules that compiled separately with type checking Fully abstract data types Objects (next chapter)

(8) Abstract Data Type A collection of data and a set of operations on that data Encapsulated: The representation of the type and the operations are in a single syntactic unit Information Hiding: The representation is hidden from client programs and only the ADT operations may be used on them Defined in terms of how (abstracted) operations change the logical properties of the data Implemented as a data structure and operations ADT ≠ data structure

(9) Specifying ADTS Pseudocode Structured natural language Informal semantics Axioms Formal semantics: prove properties No direct connection to code Java interface Formal parameters (but no semantics) Supports coding

(10) ADT List Example createList() - create an empty list isEmpty() - determine whether a list is empty add(index,item) - add an item at a given position in the list remove(index) - remove the item at a given position in the list removeAll() - remove all items from the list get(index) - retrieve the item at a given position

(11) ADT List Axioms 1. (aList.createList()).size() == 0 2. (aList.add(i,x)).size() == aList.size() (aList.remove(i)).size() == aList.size() (aList.createList()).isEmpty() == true 5. (aList.add(i,item)).isEmpty() == false 6. (aList.createList()).remove(i) = error 7. (aList.add(i,x)).remove(i) = aList 8. (aList.createList()).get(i) == error 9. (aList.add(i,x)).get(i) == x 10. aList.get(i) == (aList.add(i,x)).get(i+1) 11. aList.get(i+1) == (aList.remove(i)).get(i) Prove: ((aList.add(1,b)).add(1,a)).get(2) = b

(12) ADT List Implementations Adjacency Representation (Array) Linked Representation Can change representation without changing client code

(13) Design Issues Language should provide Syntactic unit that encapsulates definitions Header visible to clients Body hidden from clients Which operations are pre-provided? Assignment, comparison? Constructors, destructors? Iterator? Can the type be parameterized?

(14) SIMULA 67 SIMULA 67 contributed encapsulation via classes class class_name; begin class variable definitions class subprogram definitions class code end class_name; Lacked information hiding

(15) ADA Contributed information hiding Encapsulated with packages Specification package type NODE_TYPE is private; Body package package LINKED_LIST_TYPE is; type NODE_TYPE is private; private... type NODE_TYPE is record INFO: INTEGER; LINK : PTR; end record

(16) ADA Using a Package with imports packages use eliminates need for package name qualifiers with LINKED_LIST_TYPE; use LINKED_LIST_TYPE; Generic (parameterized) ADTS Example: enable linked list to store other than integers generic type ELEMENT_TYPE is private; package GENERIC_LINKED_LIST is … … ELEMENT_TYPE … // somewhere in the body Explicit Instantiation: package INTEGER_LINKED_LIST is new GENERIC_LINKED_LIST(INTEGER);

(17) C++ Uses Classes (rather than Packages) Classes are types Extension of C struct Member functions shared by all instances - Can be defined to be inlined - Recompilation issue Data members usually unique to instances Class instances are stack dynamic - But can include heap-dynamic members - Explicit management with new, delete

(18) C++ Example Public and Private Clauses Constructor and Destructor Functions class stack { private: … private members … public: stack() { … } // constructor ~stack() { … } // destructor void push(int val) { … } void pop() { … } int top() { … } int empty() { … } }

(19) C++ Generic ADTs Templated Classes template class stack { private: Type *stack_ptr; … more private members … public: stack() { … } // constructor ~stack() { … } // destructor void push(Type val) { … } void pop() { … } int top() { … } int empty() { … } } Implicit Instantiation: created when object that needs a new version is created

(20) C++ Evaluation Unlike packages, classes are types (can make instances, while you just use a package) Limitation of classes: without generalized encapsulation must choose which object to associate an operation Example: Multiplication of Matrix and Vector Friend construct makes member function available to multiple classes friend Vector multiple(const Matrix&, const Vector&); ADA solves this by putting Matrix and Vector in the same package Java does both … Provides also for OOP (next chapter)

(21) Java Most similar to C++. Main differences: All user defined types are classes (as well as all classes are types) Subprograms can only be defined as methods (member functions) Packages provide higher level encapsulations, and are hierarchical Public, private, protected, package scope Heap dynamic, implicit destruction

(22) Java Example Public and Private are modifiers, not clauses class MyStack { private int [] stackRef; private int max_len, topIndex; public myStack () { … } // constructor public void push(int val) { … } public void pop() { … } public int top() { … } public boolean empty() { … } } Parameterized ADTs handled via Abstract Classes

(23) Wednesday: OOP and examples with Python, Java