C SC 205 Lecture 9: ArrayList class implementation
major resources: Data Structures and the Java Collections Framework Second Edition,
William Collins, McGraw-Hill, 2005
Introduction to Programming and OO Design
using Java, Niño and Hosch, Wiley & Sons, 2002
[ previous
| schedule
| next ]
Wednesday October 10 (week 5)
ArrayList implementation
- Notice the use of array field to hold the collection, no surprise, but also it is declared transient.
This means it will not be serialized (see Serializable interface above) if that operation is performed.
- Implementation techniques of the three contructors
- Implementation of add() confirms that duplicates and nulls are both allowed in the list
- Overloaded add() with index may throw an exception -- what would cause this?
- What is the purpose of the arraycopy in remove()
- The private writeObject() and readObject() methods are called as part of serialization
and deserialization, respectively
OO design choices: is-a versus has-a
- You are going to design a class to represent, say, a polynomial.
- A polynomial is a collection of terms.
- You want to represent the polynomial with an ArrayList
- Should your Polynomial class extend ArrayList (is-a), or
should it have an ArrayList field instead (has-a)?
- consider the advantages and disadvantages of each approach
- Now, check out the API for java.util.Stack
- We'll cover stacks later in the term
- What about has-a as a substitute for is-a, in general?
- What about has-a as a substitute for multiple inheritance?
End of Material for the Midterm Exam
[ C
SC 205 | Peter
Sanderson | Math Sciences server
| Math Sciences home page
| Otterbein ]
Last updated:
Peter Sanderson (PSanderson@otterbein.edu)