Lecture 18 (Edwards) - Classes as Fields and Garbage Collection

Lecture Date: Wednesday, March 25

Today we will talk about using classes as fields for other classes, using the following example.

Theater
− movies : ArrayList<Movie>
− name : String
+ addMovie(Movie) : void
+ removeMovie(Movie) : void
+ isShowing(Movie) : boolean
Movie
− theaters : ArrayList<Theater>
− name : String
+ addTheater(Theater) : void
+ removeTheater(Theater) : void
+ isAt(Theater) : boolean

Then we will move on to static fields and then wrap up the class by talking about the stack and heap and then throwing away kittens (JK)!

stackvsheap

Image credit: thenewcircle.com

Code: