1 / 21

Structured Data Types and Encapsulation

Structured Data Types and Encapsulation. Mechanisms to create new data types: Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records Subprograms Type declarations – to define new types and operations (Abstract data types) Inheritance . Structured data types.

todd
Download Presentation

Structured Data Types and Encapsulation

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. Structured Data Types and Encapsulation Mechanisms to create new data types: • Structured data • Homogeneous: arrays, lists, sets, • Non-homogeneous: records • Subprograms • Type declarations – to define new types and operations (Abstract data types) • Inheritance

  2. Structured data types A data structure is a data object that contains other data objects as its elements or components.

  3. Data specifications • Number of components and size • Type of each component • Selection mechanism • Maximum number of components • Organization of the components

  4. Data specifications • Number of components and size • Fixed size - Arrays • Variable size – stacks, lists. Pointer is used to link components. • Type of each component • Homogeneous – all components are the same type • Heterogeneous – components are of different types

  5. Data specifications - selection Selection mechanism to identify components – index, pointer Two-step process: referencing the structure selection of a particular component

  6. Data specifications - organization • Simple linear sequence - arrays, stacks, lists • Multidimensional structures: • separate types (Fortran) • a vector of vectors (C++)

  7. Operations on data structures • Component selection operations • Sequential • Random • Insertion/deletion of components • Whole-data structure operations • Creation/destruction of data structures

  8. Implementation of structured data types • Storage representations • Implementation of operations on data structures • Storage management

  9. Storage representation INCLUDES: • storage for the components • optional descriptor, contains some or all of the attributes • Sequential representation • Linked representation

  10. Sequential representation the data structure is stored in a single contiguous block of storage, that includes both descriptor and components. Used for fixed-size structures, homogeneous structures (arrays, character strings)

  11. Linked representation the data structure is stored in several noncontiguous blocks of storage, linked together through pointers. Used for variable-size structured (trees, lists) Flexible, ensures true variable size, however it has to be software simulated

  12. Implementation of operations on data structures • Component selection in sequential representation • Base address plus offset calculation. Add component size to current location to move to next component. • Component selection in linkedrepresentation • Move from address location to address location following the chain of pointers.

  13. Storage management • Access paths to a structured data object - to endure access to the object for its processing. Created using a name or a pointer. • Two central problems: • Garbage– data object is bound but access path is destroyed. Memory cannot be unbound. • Dangling references: the data object is destroyed, but the access path still exists.

  14. Declarations and type checking for data structures • What is to be checked: • Existence of a selected component • Type of a selected component

  15. Vectors and arrays Vector - one dimensional array Matrix - two dimensional array Multidimensional arrays Slice - a substructure in an array that is also an array, e.g. a column in a matrix Associative Arrays - elements are selected by a key value

  16. Implementation of array operations • Access - can be implemented efficiently if the length of the components of the array is known at compilation time. • The address of each selected element can be computed using an arithmetic expression. • Whole array operations, e.g. copying an array - may require much memory.

  17. Records • A record is data structure composed of a fixed number of components of different types. • The components may be heterogeneous, and they are named with symbolic names.

  18. Other structured data objects Records and arrays with structured components Lists and sets Executable data objects Data structures are considered to be a special type of program statements and all are treated in the same way (Prolog).

  19. Abstract Data Types • An abstract data type is: • A set of data objects, • A set of abstract operations on those data objects • Encapsulation of the whole in such a way that the user of the data object cannot manipulate data objects of the type except by the use of operation defined.

  20. Information Hiding • When information is encapsulated in an abstraction, it means that the user of the abstraction • 1. Does not need to know the hidden information in order to use the abstraction • 2. Is not permitted to directly use or manipulate the hidden information even if desiring to do so.

  21. Mechanisms that support encapsulation • Subprograms • Type definitions

More Related