uuid: - value: 81e54ee3-c438-49d9-9450-27cafa5a7fae langcode: - value: en type: - target_id: daily_email target_type: node_type target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7 revision_timestamp: - value: '2025-05-11T09:00:07+00:00' revision_uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 revision_log: { } status: - value: true uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 title: - value: 'Avoiding primitive obsession' created: - value: '2024-09-09T00:00:00+00:00' changed: - value: '2025-05-11T09:00:07+00:00' promote: - value: false sticky: - value: false default_langcode: - value: true revision_translation_affected: - value: true path: - alias: /daily/2024/09/09/avoiding-primitive-obsession langcode: en body: - value: |
Something interesting that Dave Liddament and I discussed was the use of value objects in application code.
Instead of using a primitive type, such as string
, you can create a new value object for a specific type of string, such as an EmailAddress
or, in my side project, a LicenceKey
.
Both are strings, but using value objects of specific types can make the code more readable and its intent clearer.
A value object can contain additional logic, such as validation to execute an ensure the value object is valid, such as making sure a string is not empty, is a specific length or only contains valid characters.
This an approach that I'm going to use more going forward.
I also found a lighting talk by Dave at a PHPSW meetup where he explains this further and, of course, you can listen to the podcast episode after it's been released.
format: full_html processed: |Something interesting that Dave Liddament and I discussed was the use of value objects in application code.
Instead of using a primitive type, such as string
, you can create a new value object for a specific type of string, such as an EmailAddress
or, in my side project, a LicenceKey
.
Both are strings, but using value objects of specific types can make the code more readable and its intent clearer.
A value object can contain additional logic, such as validation to execute an ensure the value object is valid, such as making sure a string is not empty, is a specific length or only contains valid characters.
This an approach that I'm going to use more going forward.
I also found a lighting talk by Dave at a PHPSW meetup where he explains this further and, of course, you can listen to the podcast episode after it's been released.
summary: null field_daily_email_cta: { }