Download
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
ADT PowerPoint Presentation

ADT

219 Vues Download Presentation
Télécharger la présentation

ADT

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. ADT data abstraction

  2. Abstraction • representation of concepts by their relevant features only • programming has two major categories of abstraction • process abstraction (procedures) • data abstraction (abstract data types -> objects)

  3. Process abstraction • external view: for caller of procedure – only the preconditions and effect of the process are relevant • internal view: for implementer of procedure – details of how to achieve effect starting from preconditions are important

  4. Process abstraction • advantages • reusable procedures • revision of procedures independent of usage -> model for large programming projects – control of complexity, separation of tasks

  5. Steps toward ADT • process abstraction inadequate – not enough organizing structure • modules • group related procedures (and data) together • compilation units • make groups as independent as possible (avoid recompilation – recall distinction of separate and independent compilation)

  6. Steps toward ADT • encapsulation • independently compilable units with support for internal structure • visible interfaces for use by other units using them (types, procedure protocols, for error checking)

  7. Abstract Data type (think Objects) • encapsulation for one data type (record?) and its operations e.g. complex number type with arithmetic ops • user program can create instances and apply operations • user program cannot manipulate (or even see) internal structure

  8. Complex number ADT • ADT to represent and operate on complex numbers • behaviour - external • representation of a complex number • operations on complex number objects • implementation - internal • internal variables • methods code

  9. Complex number ADT ADT Cpx • behaviour • representation of a complex number • string: “3 - 4i” or “(5,pi/4)” • operations on complex number objects • new(real, imaginary); new(magnitude, angle) • getReal, getImaginary, getMagnitude, getOrientation • add, subtract, multiply, divide, power • e.g., function add(Cpx x,Cpx y)returns Cpx

  10. Complex number ADT ADT Cpx • implementation - internal • internal variables • double real • double im • methods code • function add(Cpx x,Cpx y)returns Cpx z = new Cpx(x.real+y.real, x.im+y.im) return z

  11. User defined ADTs • language capability for programmer to create, compile and use new ADTs the same way as built-in ADTs • compile to make types, protocols visible with implementation invisible • any built-in/”inherited” features for all ADTs? e.g. copy, compare, assign • any restrictions on ADT types? simplicity/flexibility tradeoff e.g. parameterized ADTs, references only

  12. Ada C++ Java Package Class Package and class Specification package (interface info for independent compilation) And Body package (implementation of procedures) p. 480 Class with privacy controls for information hiding NO higher level structure like package Friend functions with access to private structure Class with privacy controls And Package for organizing and mutual access EVERYTHING is ADTs (no independent methods/functions)

  13. Ada C++ Java Package Class Package and class Contains (many) types and procedures NOT methods Parameterized e.g. collection package usable for different element types Template classes can be used with different types Instances of classes are allocated on run-time stack (may contain heap dynamic instance variables) Generic classes; Wrapper classes Object hierarchy provides same power (except for primitive types) Only references are on run-time stack – all instance objects on heap

  14. Ada format • Specification package • Types • Procedure protocols • Some are ‘private’ – invisible to user programs • Body package • procedure code

  15. Java abstraction concepts - ADTs and more --> objects • class • interface • abstract class • generic class • inheritance hierarchy • wrapper class