Data structure vs Objects

Reading through the Clean Code book, I stumbled upon a very strong and deep piece of advice:

Mature programmers know that the idea that everything is an object is a myth. Sometimes you really do want simple data structures with procedures operating on them.

Batman (Clean code) slapping Robbin (purist OO developer): everything is an object. That is a myth!
Chapter 6: Objects and Data Structures, that is nearly a slap on the face of purist Object-Oriented developers.

However right before that, Uncle Bob…

Photo by AbsolutVision on Unsplash

Just a quick note to talk about a pattern to lazy load constants (similar to an old question in Stackoverflow).

Sometimes you have a class full of constants and some of those are resource intensive (CPU or memory).

Lazy load those constants:

public static final Map<String, String> ISO_TO_SYMBOL {
get {
if (ISO_TO_SYMBOL == null) {
ISO_TO_SYMBOL = new Map<String, String>{
'USD' => '$',
'CAD' => '$',
'EUR' => '€',
'GBP' => '£',
'JPY' => '¥',
'KRW' => '₩',
'CNY' => '元'
};
}
return ISO_TO_SYMBOL;
}
set;
}
  1. Assure the static instance is never changed: constant.
  2. Load the map only if requested: lazy load.
  1. More convoluted code.

Is this a supported pattern or just a corner case? Asking because have not found an example online.

Jeferson Spencer Chaves

I’m a Software Engineer working with Salesforce Lightning Platform @Waeg.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store