Abstract Data Type.

Slides:



Advertisements
Similar presentations
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Advertisements

Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.
Implementation options There are two basic approaches: –array-based –linked We will consider array-based implementation first Use a TDD approach: first.
Copyright W. Howden1 Lecture 13: Programming by Contract.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Information Hiding and Encapsulation
Rossella Lau Lecture 5, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 5: Class construction  Encapsulation 
Chapter 1 Principles of Programming and Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Chapter 11: Classes and Data Abstraction
ASP.NET Programming with C# and SQL Server First Edition
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
From Use Cases to Test Cases 1. A Tester’s Perspective  Without use cases testers will approach the system to be tested as a “black box”. “What, exactly,
Data Structures and Abstractions with Java, 4e Frank Carrano
Chapter 11: Classes and Data Abstraction. C++ Programming: Program Design Including Data Structures, Fourth Edition2 Objectives In this chapter, you will:
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Chapter 24 Exception CSC1310 Fall Exceptions Exceptions Exceptions are events that can modify the flow or control through a program. They are automatically.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Data Structures: CSCI Chapter 1 Data Structures: CSCI Chapter 1 lecture notes adapted from Data Structures with C++ using STL Dr. Nazli Mollah.
Introduction to Object-Oriented Programming Lesson 2.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Defensive Programming CNS 3370 Copyright 2003, Fresh Sources, Inc.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 12: Classes and Data Abstraction.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 05: Classes and Data Abstraction.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Introduction to Objects and Encapsulation Computer Science 4 Mr. Gerb Reference: Objective: Understand Encapsulation and abstract data types.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
Chapter 2 Principles of Programming and Software Engineering.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
XuanTung Hoang 1 Something to discuss Feedbacks on Midterm Exam Final exam and term project  Final exam requires solid knowledge/skills in Java  Be more.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
2.4 Exceptions n Detects try { //code that may raise an exception and/or set some condition if (condition) throw exceptionName; //Freq. A string } n Handles.
Advanced Data Structures Lecture 1
Principles of Programming & Software Engineering
Data Abstraction: The Walls
Chapter 6 CS 3370 – C++ Functions.
Abstract Data Types and Encapsulation Concepts
CIS 200 Test 01 Review.
More JUnit CS 4501 / 6501 Software Testing
Chapter 1 Data Abstraction: The Walls
Principles of Programming and Software Engineering
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
CSE 143 Error Handling [Section 2.8] 3/30/98 CSE 143.
Chapter 14: Exception Handling
Classes and Objects 2nd Lecture
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
structures and their relationships." - Linus Torvalds
Slides by Steve Armstrong LeTourneau University Longview, TX
CSC 143 Error Handling Kinds of errors: invalid input vs programming bugs How to handle: Bugs: use assert to trap during testing Bad data: should never.
Learning Objectives Classes Constructors Principles of OOP
Dynamic Data Structures and Generics
Coding Concepts (Basics)
ERRORS AND EXCEPTIONS Errors:
Defining Classes and Methods
Information Hiding and Encapsulation Section 4.2
structures and their relationships." - Linus Torvalds
Presentation transcript:

Abstract Data Type

Consider the examples … The Date class we saw in CSCI 203 d = Date() tomorrow = d.nextDay() gives a new date d.is_week_day() gives True of False A GradeBook class b = GradeBook(student_list, course_list) print(b.get_grade(‘Sam Brown’, ‘CSCI 204’))

What’s in common? In both cases, we (the application program) just wanted to use the pre-built class (Date or GradeBook). We don’t care how Date or GradeBook was implemented. We are not supposed to visit or change the implementation of Date or GradeBook classes. Using ADT makes our lives much easier! We don’t need to re-invent the wheels!

Abstract Data Type An abstract data type (ADT) is a collection of data and a set of operations on the data. An ADT has the following features. Information Hiding: It hides implementation details from the users. That is, it presents what the ADT does, not how it does. It provides an interface that other programs can use to access the functionality of the ADT.

Information Hiding ADTs can be viewed as black boxes: functionality is provided through an interface. Matrix in the coming lab! implementation details are hidden inside the box.

Types of Operations ADT operations can be grouped into four categories: constructors – creates it accessors – gets information mutators – changes information iterators – navigates through it

What does information hiding look like? Date example Counter example Inventory example You will be working on Matrix in the coming lab

Using the ADT We can use the ADT without knowing how it's implemented. Reinforces the use of abstraction: by focusing on what functionality is provided instead of how that functionality is implemented.

Defining Operations The ADT definition should specify: required inputs and resulting outputs. state of the ADT instance before and after the operation is performed.

Preconditions Condition or state of the ADT instance and data inputs before the operation is performed. Assumed to be true. Error occurs if the condition is not satisfied. ex: index out of range Implied conditions the ADT instance has been created and initialized. valid input types.

Postcondition Result or state of the ADT instance after the operation is performed. Will be true if the preconditions are met. given: x.pop(i) the ith item will be removed if i is a valid index.

Postcondition The specific postcondition depends on the type of operation: Access methods and iterators no postcondition. Constructors create and initialize ADT instances. Mutators the ADT instance is modified in a specific way.

Exceptions OOP languages raise exceptions when errors occur. Example: An event that can be triggered by the program. Optionally handled during execution. Example: my_list = [ 12, 50, 5, 17 ] print( my_list[4] ) Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: list index out of range

Assertions Used to state what we assume to be true. If condition is false, a special exception is automatically raised. Combines condition testing and raising an exception. Exception can be caught or let the program abort. assert value != 0, “Value cannot be zero.”

Evaluating a Data Structure Evaluate the data structure based on certain criteria. Does the data structure: provide for the storage requirements of the ADT? provide the necessary functionality to fully implement the ADT? lend itself to an efficient implementation of the operations?

Selecting a Data Structure Multiple data structures may be suitable for a given ADT. Select the best possible based on the context in which the ADT will be used. Common for language libraries to provide multiple implementations of a single ADT.

Build a Bag Think of this ADT like a shopping cart. Items can be added to it. Items can also be removed from it. However, there is no specific order to them. Operations: add: which adds an item to the bag remove: which removes an item from the bag contains: which checks if an item is in the bag iterator: which traverses over the items in the bag one at a time