Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Abstaraction Chapter 10.

Similar presentations


Presentation on theme: "Data Abstaraction Chapter 10."— Presentation transcript:

1 Data Abstaraction Chapter 10

2 Outline Concept of abstraction Abstract data types with example
Encapsulation with example

3 The Concept of Abstraction
Say what a program does without necessarily saying how it does it A process of generalization, removing restrictions, eliminating detail, removing inessential information etc “more potential implementations” – moving to a lower level mans restricting the number of potential implementations

4 Data types A data type is characterized by: a set of values
a data representation, which is common to all these values, and a set of operations, which can be applied uniformly to all these values

5 Abstract Data Types (ADTs)
C is not object-oriented, but we can still manage to inject some object-oriented principles into the design of C code. For example, a data structure and its operations can be packaged together into an entity called an ADT. The lower-level implementation details of the data structure are hidden from view of the rest of the program. The implementation details can be changed without altering the ADT interface.

6 Abstract Data Types (ADTs)
Data abstraction + operation abstraction An abstract data type consists of: Data structure: stores information to represent a certain concept Functionality: set of operations that can be applied to the data type

7 ADT : Example As an example the description of the ADT Integer is presented. Let k be an integer expression: ADT Integer is Data A sequence of digits optionally prefixed by a plus or minus sign. We refer to this signed whole number as N. Operations constructor Creates a new integer. add(k) Creates a new integer which is the sum of N and k. Consequently, the postcondition of this operation is sum = N+k. Don't confuse this with assign statements as used in programming languages! It is rather a mathematical equation which yields ``true'' for each value sum, N and k after add has been performed. sub(k) Similar to add, this operation creates a new integer of the difference of both integer values. Therefore the postcondition for this operation is sum = N-k. set(k) Set N to k. The postcondition for this operation is N = k. ... end

8 Properties of Abstract Data Types
The entities define the data structure of a set of items. For example, each administered employee has a name, date of birth and social number. The data structure can only be accessed with defined operations. This set of operations is called interface and is exported by the entity. An entity with the properties just described is called an abstract data type (ADT).

9 Properties of Abstract Data Types (con’t)
Figure below shows an ADT which consists of an abstract data structure and operations. Only the operations are viewable from the outside and define the interface. Separate the use of a data structure from the details of its implementation. This is the principle underlying the use of abstract data types. Here are some examples: stack: operations are "push an item onto the stack", "pop an item from the stack", "ask if the stack is empty"; implementation may be as array or linked list or whatever. queue: operations are "add to the end of the queue", "delete from the beginning of the queue", "ask if the queue is empty"; implementation may be as array or linked list or heap. search structure: operations are "insert an item", "ask if an item is in the structure", and "delete an item"; implementation may be as array, linked list, tree, hash table, ...

10 Implementing an ADT To implement an ADT, you need to choose:
a data representation that must be able to represent all possible values of the ADT should be private a set of methods that support normal use of the ADT The user must be able to create, possibly modify, and examine the values of the ADT an algorithm for each of the possible operations that must be consistent with the chosen representation all auxiliary (helper) operations that are not in the contract should be private

11 Abstract Data Types: Benefits
Domain concepts are reflected in the code Encapsulation: internal complexity, data and operation details are hidden Specification vs. implementation: usage of data type is independent from its internal implementation Higher modularity Increase ease of maintenance and reuse of code

12 ADT : Programming example

13 ADT Extensibility

14 Encapsulation Focus on the external behavior of something and ignores the internal details of how the behavior is produced Different part of the software to be effectively isolated in operation Any component has one or more simple, well-defined external interfaces (defined in a standard)

15 Encapsulation and Objects

16 Encapsulation : Object example
Optical and wired Wheeled and wireless Optical and wireless

17 Encapsulation : Benefits

18 Summary Abstraction Data Types Benefits of using ADT Encapsulation
Operations Benefits of using ADT Encapsulation Implementation in C language Objects Advantages


Download ppt "Data Abstaraction Chapter 10."

Similar presentations


Ads by Google