Chapter 2. Reference implementation
This chapter covers
- Using standard collections
- Creating diagrams to illustrate a software design
- Expressing performance in big-O notation
- Estimating the memory footprint of a class
In this chapter, you’ll examine a version of the Container class that strikes a good balance between different qualities, such as clarity, efficiency, and memory usage.
As you recall from section 1.7, I made the assumption that storing and maintaining the set of indirect connections between containers would suffice. In practice, you do this by equipping each container with a reference to the collection of containers directly or indirectly connected to it, called its group. Being familiar with the Java Collections Framework (JCF) (see sidebar), let’s go hunting for the best class to represent one of these groups.
Java Collections Framework
Most standard collections were introduced in Java 1.2 and were heavily redesigned for the 1.5 release (later renamed Java 5) to take advantage of the newly introduced generics. The resulting API is called the JCF and is one of the crown jewels of the Java ecosystem. It comprises approximately 25 classes and interfaces, providing common data structures such as linked lists, hash tables, and balanced trees, as well as concurrency-oriented facilities.