ISBN 0- 321-49362-1 Chapter 11 Abstract Data Types and Encapsulation Concepts.

Slides:



Advertisements
Similar presentations
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
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.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
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.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 12 Topics Introduction Object-Oriented Programming.
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.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 5 Names, Bindings, and Scopes. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 5 Topics Introduction Names Variables The Concept.
ISBN Chapter 5 Names, Bindings, and Scopes.
Learners Support Publications Classes and Objects.
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
ISBN Chapter 5 Names, Bindings, and Scopes.
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.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
Chapter 12 Support for Object-Oriented Programming.
Object-Oriented Programming Chapter Chapter
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
ISBN Object-Oriented Programming Chapter Chapter
ISBN Chapter 9 Subprograms. Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley.
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.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
ISBN Chapter 10 Implementing Subprograms.
ISBN Chapter 12 Support for Object-Oriented Programming.
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
Abstract Data Types and Encapsulation Concepts
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Implementing Subprograms
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Chapter 11 Abstract Data Types and Encapsulation Concepts
Classes and Objects.
Support for Object-Oriented Programming
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
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:

ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized Abstract Data Types Encapsulation Constructs Naming Encapsulations

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. The Concept of Abstraction An abstraction is a view or representation of an entity that includes only the most significant attributes The concept of abstraction is fundamental in programming (and computer science) Nearly all programming languages support process abstraction with subprograms Nearly all programming languages designed since 1980 support data abstraction

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Introduction to Data Abstraction An abstract data type is a user-defined data type that satisfies the following two conditions: –The representation of, and operations on, objects of the type are defined in a single syntactic unit –The representation of objects of the type is hidden from the program units that use these objects, so the only operations possible are those provided in the type's definition

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Advantages of Data Abstraction Advantage of the first condition –Program organization, modifiability (everything associated with a data structure is together), and separate compilation Advantage the second condition –By hiding the data representations, user code cannot directly access objects of the type or depend on the representation, allowing the representation to be changed without affecting user code

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Language Requirements for ADTs A syntactic unit in which to encapsulate the type definition A method of making type names and subprogram headers visible to clients, while hiding actual definitions

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Language Examples: C++ The class is the encapsulation device All of the instances of a class share a single copy of the member functions Each instance of a class has its own copy of the class data members Instances can be static, stack dynamic, or heap dynamic

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Language Examples: C++ (continued) Information Hiding –Private clause (for hidden entities) –Public clause (for interface entities) –Protected clause (for entities that should be visible in subclasses, but not from the outside)

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Language Examples: C++ (continued) Constructors: –Methods to initialize the data members of instances (they do not create the objects) –May also allocate storage if part of the object is heap-dynamic –Can include parameters to provide parameterization of the objects –Implicitly called when an instance is created –Name is the same as the class name

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Language Examples: C++ (continued) Destructors –Methods to cleanup just before an instance is destroyed; usually just to reclaim heap storage –Implicitly called when the object’s lifetime ends –Name is the class name, preceded by a tilde (~)

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Language Examples: C++ (continued) Friend functions or classes - to provide access to private members to some unrelated units or functions –Necessary in C++

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. An Example in C++ class stack { private: int *stackPtr, maxLen, topPtr; public: stack() { // a constructor stackPtr = new int [100]; maxLen = 99; topPtr = -1; }; ~stack () {delete [] stackPtr;}; void push (int num) {…}; void pop () {…}; int top () {…}; int empty () {…}; }

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Parameterized Abstract Data Types Parameterized ADTs allow designing an ADT that can store any type elements (among other things) Also known as generic classes C++, Ada, Java, and C# provide support for parameterized ADTs

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Parameterized ADTs in C++ The stack element type can be parameterized by making the class a templated class template class stack { private: Type *stackPtr; const int maxLen; int topPtr; public: stack() { stackPtr = new Type[100]; maxLen = 99; topPtr = -1; } … }

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Encapsulation Constructs Large programs have two special needs: –Some means of organization, other than simply division into subprograms –Some means of partial compilation (compilation units that are smaller than the whole program) Obvious solution: a grouping of subprograms that are logically related into a unit that can be separately compiled (compilation units) Such collections are called encapsulation

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Nested Subprograms Organizing programs by nesting subprogram definitions inside the logically larger subprograms that use them Some languages featuring nested subprograms: Pascal, Ada, Fortran 95, Python, and Ruby

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Encapsulation in C Files containing one or more subprograms can be independently compiled The interface is placed in a header file Variables and functions defined in the file can be hidden from the outside world through the static keyword #include preprocessor specification – used to include header files in applications

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Encapsulation in C++ Similar to C Classes can act as an additional encapsulation mechanism, where related functions are grouped under a class umbrella. Common global data can be kept in class variables.

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Ada Packages Ada specification packages can include any number of data and subprogram declarations Ada packages can be compiled separately A package’s specification and body parts are in separate files and can be compiled individually

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Naming Encapsulations Large programs define many global names; need a way to divide into logical groupings A naming encapsulation is used to create a new scope for names C++ / C# Namespaces –Can place each library in its own namespace –Qualify names used outside with the namespace

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Naming Encapsulations (continued) Java Packages –Packages also create namespaces –Packages can contain more than one class definition –Clients of a package can use fully qualified name or use the import declaration

Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley. All rights reserved. Summary The concept of ADTs and their use in program design was a milestone in the development of languages Two primary features of ADTs are the packaging of data with their associated operations and information hiding Ada provides packages that can be used to implement ADTs C++, C#, Java provide data abstraction through classes Ada, C++, Java 5.0, and C# 2005 support parameterized ADTs C++, C#, Java, Ada provide naming encapsulations