Flyweight (Chapter 13)
SOLUTION 13.1 | The BorderFactory class in javax.swing is a good example of FLYWEIGHT. As its class comment says, “Wherever possible, this factory will hand out references to shared Border instances.” When a Border object can be safely shared, BorderFactory will return the same border more than once. For example, every call to createEmptyBorder() will return the same, empty border. |
SOLUTION 13.2 |
|
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.