1 / 19

5 – Abstract Data Types

5 – Abstract Data Types. Overview:. 1. What is Data Abstraction? What is ADT? 2. Model for an Abstract Data Type 3 . Complex Number ADT Example 4. How Well are ADTs Supported in C? 5. C++ 6. ADT vs Object-Oriented Programming. 1.1 What is Data Abstraction?.

warren
Download Presentation

5 – Abstract Data Types

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. 5 – Abstract Data Types

  2. Overview: 1. What is Data Abstraction? What is ADT? 2. Model for an Abstract Data Type 3. Complex Number ADT Example 4. How Well are ADTs Supported in C? 5. C++ 6. ADT vs Object-Oriented Programming

  3. 1.1 What is Data Abstraction? • Concept of “Abstraction” • Allows us to consider the high-level characteristics of something without getting bogged down in the details • For example: Process abstraction in procedural programming like C, we can use (pre-defined) functions without concern how they really works inside. • Data Abstraction • We know what a data type can do • How it is done is hidden

  4. 1.2 What is an Abstract Data Type? • Abstract Data Type (ADT) • Defines a particular data structure in terms of data and operations • Offers an interface of the objects (instances of an ADT) • An ADT consists of • Declaration of data • Declaration of operations • Encapsulation of data and operations : data is hidden from user and can be manipulated only by means of operations

  5. 1.3 ADT Implementation • Implementaion of an Abstract Data Type (ADT) • Hidden from the user • Same ADT may be implemented in different ways in different languages • Some languages offer built-in ADTs and/or features to be used to implement ADTs (user-define types) • ADTs support modular design which is very important in software development

  6. 2.1 Model for an ADT Interface - Operations Data Structure System design with ADTs Identification of ADTs (identify data or attributes) Problem definiton Specify ADT interactions Specify ADT operations Identify object hierarchy (if using OOP) Implement ADTs

  7. client ADT use interface implementation client manufacturer’sresponsibility client 2.2 Clients and Manufacturers

  8. 2.3 Benefits • Manufacturer Benefits: • easy to modify, maintain • profitable • reusable • Client Benefits: • simple to use, understand • familiar • cheap • component–based

  9. 3. Complex Number ADT Example • A complex number has a real part and an imaginary part. e.g.: 2+4i • Interface (operations) ? • create a complex number • add, subtract, multiply, divide • print a complex number • test to see if something is complex • etc.

  10. Declare a complex number • Interface: Complex c1, c2, c3; • Possible Implementation (in C language ): struct complex { double real,imag; } typedef struct complex Complex;

  11. Create a complex number • Interface: c1 = create_complex(2, 3);/* conceptually, c1 = 2+3i */

  12. Implementation: Complex create_complex(double real, double imag) { Complex c; c.real = real; c.imag = imag; return c; }

  13. Add two complex numbers • Interface: c3 = add_complex(c1, c2);/* conceptually, c3 = c1 + c2 */

  14. Implementation: Complex add_complx(Complex c1, Complex c2) { Complex csum; csum.real = c1.real + c2.real; csum.imag = c1.imag + c2.imag; return csum; }

  15. Using the Complex Number ADT #include <stdio.h>/* type implementation */struct complex { double real,imag; typedef struct complex Complex; /* operation interface */Complex create_complex(double,double);Complex add_complex(Complex, Complex); /* other Complex prototypes print_complex() . . . */ continued

  16. Using the Complex Number ADT int main ( ){ Complex c1, c2, c3; c1 = create_complex(2,-3); c2 = create_complex(2,-3); c3 = add_complex(c1,c2); print_complex(c3); return 0; } /*Implementation of Complex functions */ :

  17. 4. How Well are ADTs Supported in C? • Does C enforce the use of the ADTs interface and the hiding of its implementation? • No

  18. 5. C++ and OOP • C++ is a superset of C, which has added features to support object oriented programming (OOP) • C++ offers STL (Standard Templates Library)providing a set generic data structureswhich allow programmers to easily implement standard data structures like queues, lists, and stacks. • C++ supports classes • things very like ADTs • Other OOP languages such as Java, Smalltalk

  19. 6. ADT vsObject-Oriented Programming (OOP) • ADTs are not a part of a particular programming language • Rather they are implemented by a programmer to solve a particular problem or some class of problems • In OOP, an ADT can be easily modeled as a class • An instance as an object • Data of ADT as properties or fields of a class • Operations as methods • ADT ≠ OOP • Classes in OOP offers more features than ADTs : Inheritance (Superclass-Subclass), Polymorphisms, etc.

More Related