Having defined the interface, you proceed to
define the class. The new class, like the Movie
class, is an
observable, with a setter that activates observers when the movie vector is
set, and a miscellaneous method, changed
that activates observers
when called.
import java.util.*; public class MovieData extends Observable implements MovieDataInterface { private Vector vector; public MovieData () { setMovieVector(MovieAuxiliaries.readMovieFile("general.movies")); } public void setMovieVector (Vector v) { vector = v; setChanged(); notifyObservers(); } public Vector getMovieVector () { return vector; } public Movie getMovie (int i) { if (i >= 0 && i <= vector.size()) { return (Movie)(vector.elementAt(i)); } else {return null;} } public void changed () { setChanged(); notifyObservers(); } }