Download CarranoTextCh3Highlights

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Carrano Text: Chapter 3 Highlights
1. ADTs (Abstract Data Types)
a. Conceptualization before construction
i. First, specification (what can be done, but not how to do it)
1. Informal
a. Example: Create an empty list
2. Based on axioms
a. Example: (aList.createList()).getLength()==0
ii. Second, implementation (how to do it)
b. An ADT embodies the notion of encapsulation
i. Attributes (implemented by data members, which are generally private)
ii. Behaviors (or operations, implemented by member functions, or methods, which are
generally public and provide whatever client access to the private data members is
permitted by the ADT designer)
c. Note that an ADT is a language-independent concept
d. It must be possible to change the implementation without changing the interface.
2. ADTs vs. Data Structures
a. ADT: A collection of data, together with a set of operations on that data
b. Data Structure: A programming language construct for storing a collection of data
3. What can we say about the data and operations of ADTs in general?
a. The data in an ADT is generally very application-specific.
b. On the other hand, there are many operations common to many ADTs:
i. Create a new instance of the ADT (in various ways) (via constructors)
ii. Test to see if an instance is empty
iii. Test to see if an instance is full
iv. Insert something into the instance (in various ways, perhaps)
v. Remove something from the instance (also in various ways, perhaps)
vi. Clear the instance of all contained data
vii. Make a copy of an instance
viii. Destroy an instance when it is no longer needed (via a destructor)
4. An ADT to Represent a List (based on the array data structure)
a. ADTList (generic)
b. ADTSortedList (specialized)
c. We will see that the STL list container relieves us from having to develop our own list.
5. Exceptions
a. Old-fashioned error-handling vs. exceptions
b. try … throw … catch
c. Kinds of exceptions
i. Values of simple data types like enum or int
ii. Built-in exception classes from <stdexcept>, including runtime exceptions such as
overflow_error or range_error, and logic exceptions such as
invalid_argument
iii. An exception class of your own, which inherits from the built-in class exception