CS 1110/1111: Introduction to Programming

Lecture 38

Announcements

Talking Points

Mutual Use Example

Often it is nice to have objects that refer to one another. For example, a Theater object might have many Movie objects it is showing, suggesting a UML class diagram like

Theater
movies : ArrayList<Movie>
addMovie(Movie) : void
removeMovie(Movie) : void
isShowing(Movie) : boolean

It also might make sense for a movie to know what theaters are showing it, suggesting a UML class diagram like

Movie
theaters : ArrayList<Theater>
addTheater(Theater) : void
removeTheater(Theater) : void
isAt(Theater) : boolean

Movie.java, Theater.java, and MovieTheaterTester.java

Data Consistency

When classes mutually refer to one another, we want to maintain consistent data: that is, we want t.isShowing(m) == m.isAt(t) to always be true for all Theater objects t and Movie objects m.

Data consistency has lots of potential problems, many related to networks:

Even without the network issues, there are still problems if we do not maintain consistency properly ourselves.

Copyright © 2014 by Luther Tychonievich. All rights reserved.