Quick Index
Overview


An Association type (or KeyValue) is a simple type:

Association
	key
	value


Key and value are generally both type "Object" (or constrained by a given problem).

Important -- the "key" type must understand the message "equals" (note that for primitive keys like strings and numbers "equals" may already be defined)

Purpose


It is common to have a requirement where one object is associated to another.

For example, a "Dictionary" may have a collection of associations to associate its keys to corresponding values.

Class Header


Java


In Java, the class header for Association would look like this:

public class Association<K, V>

Where:
	K - generic parameter for key data type
	V - generic parameter for the value data type


JavaScript


In JavaScript, the class header for Association would look like this:

class Association


Equals


Association objcts must support the method "equals".

Two associations are equal if their keys are equal.

Note that in some languages, if implementing the "equals" method, we may also have to add a parallel hash code method (i.e., "hashCode" in Java)

Download Example Code


Assocation "example" code: download

Navigation