Flyweight pattern
Creating objects costs time and resources. The best examples are Java constant string creation, Boolean.valueOf(boolean b), or Character valueOf(char c), since they never create instances; they return immutable cached instances. To speed up (and keep the memory footprint low), applications use object pools. The difference between the object pool pattern and the flyweight pattern is that the first (creation pattern) is a container that keeps mutable domain objects, while the flyweight (structure pattern) is an immutable domain object. Since they're immutable, their internal state is set on creation, and the extrinsic state is given from outside on each method call.
Most web applications use connection pools—a database connection ...
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