Chapter 17. 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 identifies 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 failing to follow 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 public methods that it exposes, and a client is any class that calls methods in the API.
Note
The code examples for this chapter can be found at:
https://github.com/MauriceNaftalin/JGC_2e_Book_Code/blob/main/src/main/java/org/jgcbook/chapter17
Avoid Anemic Domain Models
The term anemic domain model was coined by Martin Fowler (2003) to describe designs in which objects of the domain model are essentially data carriers, containing little or no business logic. In the standard model of object-oriented design, this leads to business logic becoming concentrated in the service layer. Fowler notes that “the problem with anemic domain models is that they incur all the costs of a domain model [in particular the need for persistence mappings], without ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access