oliverdavies.uk/content/node.81e54ee3-c438-49d9-9450-27cafa5a7fae.yml

68 lines
3 KiB
YAML

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: |
<p>Something interesting that <a href="https://www.daveliddament.co.uk">Dave Liddament</a> and I discussed was the use of value objects in application code.</p>
<p>Instead of using a primitive type, such as <code>string</code>, you can create a new value object for a specific type of string, such as an <code>EmailAddress</code> or, in my side project, a <code>LicenceKey</code>.</p>
<p>Both are strings, but using value objects of specific types can make the code more readable and its intent clearer.</p>
<p>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.</p>
<p>This an approach that I'm going to use more going forward.</p>
<p>I also found <a href="https://www.youtube.com/watch?v=yJpvObzKewY">a lighting talk by Dave</a> at a PHPSW meetup where he explains this further and, of course, you can listen to the podcast episode after it's been released.</p>
format: full_html
processed: |
<p>Something interesting that <a href="https://www.daveliddament.co.uk">Dave Liddament</a> and I discussed was the use of value objects in application code.</p>
<p>Instead of using a primitive type, such as <code>string</code>, you can create a new value object for a specific type of string, such as an <code>EmailAddress</code> or, in my side project, a <code>LicenceKey</code>.</p>
<p>Both are strings, but using value objects of specific types can make the code more readable and its intent clearer.</p>
<p>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.</p>
<p>This an approach that I'm going to use more going forward.</p>
<p>I also found <a href="https://www.youtube.com/watch?v=yJpvObzKewY">a lighting talk by Dave</a> at a PHPSW meetup where he explains this further and, of course, you can listen to the podcast episode after it's been released.</p>
summary: null
field_daily_email_cta: { }