Simberon Design Minute
 

Parallel Collections

There are some code smells that tell you that you might be missing objects. One I often see is parallel collections. These are multiple collections of data where every element of the first collection is associated with an element of a second or third collection. For example, you might find an object that has one instance variable with a collection of filenames, another instance variable with a collection of the corresponding file creation dates, and another instance variable with a collection of the corresponding modification dates. This pattern screams out for a new object. Create a new class that contains a filename, its creation date and its modification date and use one instance variable to hold a collection of these objects. You'll likely find that this new object can take on some valuable behavior and simplify your design.

Download