associations

associations - Computer Science 211 Data Structures Mount...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science 211 Data Structures Mount Holyoke College Fall 2009 Topic Notes: Associations Let’s consider a very simple example of a data structure called an Association . As the name suggests, an Association is a way to associate pairs of objects, one of which is the key and one of which is the value . Once created, the key cannot be changed, but the value can. Unlike the structures we have seen so far, this is a “general purpose” structure. What should such a structure look like? What instance variables will it need? What constructors should be provided? What methods will it need? As we have seen, in Java, all objects that are not primitive types are extensions of the class java.lang.Object , or just Object . This is very convenient when developing data struc- tures, since we can develop our structures to hold references to Object s and then use them to store instances of any Java class. This includes String s. Note: very soon we will look at the idea of generics , which was introduced into Java a few years ago and to our textbook and the structure package shortly after. But for the moment, we will make use of the fact that all Java objects are instances of class Object for our data structures. The text has an example that uses Association s to associate words with their “pig latin” equiva- lents. We will use Associations in a similar example that associates magic spells with a description
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/15/2010.

Page1 / 3

associations - Computer Science 211 Data Structures Mount...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online