Chapter 16. Guidance for Using the Java Collections Framework

The Java Collections Framework has been heavily used by millions of working Java programmers since it first appeared in 1998, a quarter-century ago at the time of this writing. The material in this chapter will identify some lessons we can derive from this collective experience. Even items that may seem elementary are worth stating explicitly; all the guidance in this chapter is based on experience with real-world code, where ignoring it has resulted in systems that are fault-prone or difficult to maintain.

In this chapter, the terms library, API, and client are used with the following meanings: a library is any class that exposes a public method, its API is the collection of the public methods that it exposes, and a client is any class that calls methods in the API.

Avoid Anemic Domain Models

The term “anemic domain model” was coined by Martin Fowler (???) to describe ...

Get Java Generics and Collections, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.