1 / 28

Procedural abstraction Information hiding

Procedural abstraction Information hiding. Abstract Data Types (ADT). Figure 3.1 Isolated tasks: the implementation of task T does not affect task Q. Figure 3.2 A slit in the wall. Add data to a data collection Remove data from a data collection

gravesl
Download Presentation

Procedural abstraction Information hiding

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. Procedural abstraction Information hiding Abstract Data Types (ADT)

  2. Figure 3.1 Isolated tasks: the implementation of task T does not affect task Q

  3. Figure 3.2 A slit in the wall

  4. Add data to a data collection Remove data from a data collection Ask questions about the data in a data collection Operations on data

  5. An abstract data type -- a collection of data and a set of operations on that data. A data structure -- a construct within a programming language that stores a collection of data. ADTs vs. Data Structures

  6. Figure 3.3 A dispenser of chilled water, crushed ice, and ice cubes

  7. Figure 3.4 A wall of ADT operations isolates a data structure from the program that uses it

  8. Figure 3.5 A grocery list

  9. Create an empty list. Determine whether a list is empty. Determine the number of items on a list. Add an item at a given position in the list. Remove the item at a given position in the list. Remove all the items from the list. Retrieve (get) the item at a given position in the list. ADT List Operations

  10. createList() isEmpty() size() add(index, item) remove(index) removeAll() get(index) ADT List Operations-Pseudocode

  11. To get a list of the following items: milk, eggs, butter, apples, bread, chicken First, declare aList as an object of List Then, aList.createList() aList.add(0, milk) aList.add(1, eggs) aList.add(2, butter) aList.add(3, apple) aList.add(4, bread) aList.add(5, chicken) ADT List Operations-Pseudocode

  12. After the following statement aList.add(3, nuts) The list will be milk, eggs, butter, nuts, apples, bread, chicken If the following operation is performed aList.remove(4) The list will be milk, eggs, butter, nuts, bread, chicken ADT List Operations-Pseudocode

  13. Once the behavior (basic operations) of an ADT is designed, access and manipulation of the ADT’s data can be defined based on its operations. displayList - displays all the items on the list aList. replace - replaces the ith item on the list aList with newItem. Access and Manipulation of ADT’s Data

  14. displayList(aList) for (index = 0 through aList.size() - 1) { dataItem = aList.get(index) Display dataItem } Access and Manipulation of ADT’s Data - displayList

  15. replace(aList, i, newItem) if (i >= 0 and i < aList.size()) { aList.remove(i) aList.add(i, newItem) } Access and Manipulation of ADT’s Data - replace

  16. Figure 3.6 The wall between displayList and the implementation of the ADT list

  17. Make an appointment for a certain date, time, and purpose. Cancel the appointment for a certain date and time. Check whether you have an appointment at a given time and date. Determine the purpose of the appointment at a given time and date. ADT for appointment book

  18. createAppointmentBook() isAppointment(date, time) makeAppointment(date, time, purpose) cancelAppointment(date, time) checkAppointment(date, time) More operations based on the operations above, e.g. change the date or time of a particular appointment within the existing appointment book. What needs to be done to achieve that? ADT appointment -Pseudocode

  19. Get the purpose of the old appointment Check if the new date and time is available to appointment If yes, make the appointment at new date and time. If no, remind the user of the existing appointment and the failure to make the new appointment. ADT appointment -Pseudocode

  20. Java Classes (class Sphere) Java Inheritance (class ColoredSphere) Java Interfaces Java Exceptions Implementing ADTs in Java

  21. Figure 3.7 ADT operations provide access to a data structure

  22. Figure 3.8 Violating the wall of ADT operations

  23. Figure 3.9 An object’s data and methods are encapsulated

  24. createList() isEmpty() size() add(newPosition, newItem) remove(index) removeAll() get(index, dataItem) An Array-Based Implementation of the ADT List

  25. Figure 3.10 An array-based implementation of the ADT list

  26. Figure 3.11 Shifting items for insertion at index 2

  27. Figure 3.12 a) Deletion causes a gap; b) fill gap by shifting

More Related