Extracting the Immutable Part of a Flyweight

Around Oozinoz, chemicals are as prevalent as characters in a document. The purchasing, engineering, manufacturing, and safety departments are all concerned with directing the flow of thousands of chemicals through the factory. Batches of chemicals are often modeled with instances of the Substance_1 class, as shown in Figure 13.1.

Figure 13.1. A Substance_1 object models a physical batch of chemical material.

The Substance_1 class has get- methods for its attributes and also has a getMoles() method that returns the number of moles—a count of molecules—in the substance. For example, 32 grams of sulfur ...

Get Design Patterns Java™ Workbook 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.