1 / 20

Abstract Data Types and Object-Oriented Programming

Abstract Data Types and Object-Oriented Programming. Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University. Process Abstraction.

mirit
Download Presentation

Abstract Data Types and Object-Oriented Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Abstract Data Types and Object-Oriented Programming Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University PLC Summer 2002

  2. Process Abstraction • Abstraction is the process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics1 • For processes • Essential characteristics • name • Type signature • Environment variables used/side-effected • Non-essential characteristics • Implementation • Abstractions are used through “interfaces”, and are supported by their implementation 1http://whatis.techtarget.com PLC Summer 2002

  3. Encapsulation • Data cannot be abstracted independently from the processes that act upon them • Collections of programs can be organized along with the data they manipulate • For abstraction of Programs+Data • For independent compilation of “modules” PLC Summer 2002

  4. Modules • Groups of logically related subprograms and data • This is the concept of encapsulation • Another opportunity for abstraction • Interface is composed of • Data • Procedures • Not all data or procedures are visible through the interface •  information hiding PLC Summer 2002

  5. Information Hiding • As part of the abstraction barrier, the following hidings may be in place • Procedures • The implementation of the procedure is hidden, only the interface is known • Types • The type may be “opaque” • Names • names (of variables, constants, procedures, etc.) may be hidden or available • Note how Ada separates interfaces from their implementation PLC Summer 2002

  6. Abstract Data Types in Languages • Every data type can be considered an “Abstract Data Type” • Integers • Floating Points • Pairs • Lists • Bignums • etc. • Can users create ADT’s? PLC Summer 2002

  7. ADT in Languages • Ada ==> packages • C++ ==> classes • Java ==> classes • Modula2 ==> modules PLC Summer 2002

  8. Interface Operations create(stack) destroy(stack) empty(stack) push(stack,element) pop(stack) top(stack) Values MAX_SIZE Types STACKTYPE Implementation Definitions for Operations STACKTYPE Initialization for such a data structure How are stacks implemented? Arrays Lists Hash tables ADT Example (Stack) PLC Summer 2002

  9. Parameterized ADT • Type systems put restrictions to ADT’s • Your book’s stack ADT works on integers • However stacks operate on any data • stacks of reals • stacks of stacks of integers • Parameterize the ADT with respect to certain key types • parameterize the stack ADT with respect to the element type PLC Summer 2002

  10. Parameterized ADT • Parameterized ADT’s are specifications that need these parameter types to become real ADT’s • Supply the element type to the generic stack ADT • Each instantiation of the parameterized ADT usually results in code specific to the supplied types • This shouldn’t be, but it’s a consequence of type systems, and the way data is implemented PLC Summer 2002

  11. Parameterized ADT in Languages • Ada ==> generic packages • C++ ==> templates • Java ==> tba in v.1.5 • Modula2 ==> modules PLC Summer 2002

  12. Example • Page 446 of your book PLC Summer 2002

  13. Object-Oriented Programming • ADT’s, plus • Inheritance • A “better” type system PLC Summer 2002

  14. Vocabulary • Class ==> ADT • Object ==> ADT instance • Derived class or sub class ==> A class that is based on another • Parent class ==> A class on which another is based • method ==> a procedural element of a class • message ==> a call to a method • property ==> a non-procedural element of a class PLC Summer 2002

  15. Inheritance • Not all ADT’s are defined at the same level • Hierarchy of data types • Newly defined data types can make use of existing ADT’s • take useful definitions • add new ones • override others PLC Summer 2002

  16. Polymorphism • The type system has been extended to allow for “subtypes” • objects from derived classes are accepted in contexts where the parent class is declared • the actual class of objects • is not known at compile time • will be known at run time • Note that deriving does not always result in subtyping PLC Summer 2002

  17. Implementation vs Interface Inheritance • Interface inheritance • only the interface of the parent class is known to derived classes • Implementation inheritance • the implementation details are also known to derived classes • With implementation inheritance, changing the implementation of the parent class will require recompilation of derived classes PLC Summer 2002

  18. Single vs Multiple Inheritance • Multiple Inheritance has its issues on method and property duplication • Should a language allow multiple inheritance • C++ does • Java does not PLC Summer 2002

  19. Allocation & Deallocation • Allocation on the stack or on the heap • Explicit or implicit deallocation PLC Summer 2002

  20. Dynamic vs Static Binding • When do bindings of messages to methods take place? • Static ==> static class • Dynamic ==> dynamic class PLC Summer 2002

More Related