Whole Value Pattern

I often forget the name of this thing, then I search for it, and forget it again later.

It’s the Whole Value Pattern.

The “Whole Value” pattern means you should get rid of using primitive or literal data types as quickly as possible. (Since Swift has no non-object primitives, you have to look a bit harder to spot these, but “literal value” is a pretty good indicator.)

Example: Instead of passing an Int of the value 21 around, create a Weeks(3) object to properly carry the meaning or intent with it.

Primitive types can represent anything; specialized objects cannot.

I’m not certain if Foundation’s Date type counts. It represents a point in time better than, say, the millisecs() timestamp return value. But it’s also different from e.g. Weeks or Days, or a proper Money type (which you should get quickly if anyone on your team try to model currency as floating point values!).

(My fairly old notes on this pattern reference “The CHECKS Pattern Language of Information Integrity” for details. The whole c2.com website is a source of amazing stuff.)