<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jim McKeon</title>
    <description>The latest articles on DEV Community by Jim McKeon (@mckeondev).</description>
    <link>https://dev.to/mckeondev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3824646%2F2622ca35-d934-4b47-8267-614c73a7029d.jpeg</url>
      <title>DEV Community: Jim McKeon</title>
      <link>https://dev.to/mckeondev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mckeondev"/>
    <language>en</language>
    <item>
      <title>Design or Debug</title>
      <dc:creator>Jim McKeon</dc:creator>
      <pubDate>Sun, 05 Jul 2026 20:18:01 +0000</pubDate>
      <link>https://dev.to/mckeondev/design-or-debug-2jpf</link>
      <guid>https://dev.to/mckeondev/design-or-debug-2jpf</guid>
      <description>&lt;h2&gt;
  
  
  A Familiar Frustration
&lt;/h2&gt;

&lt;p&gt;It’s 4 p.m. on a Friday, and I’ve spent the day working on a new high-priority enhancement. We discussed the requirements over email, chat, video calls, and several standups, and each time I walked away from these interactions reasonably confident that I understood the ask.&lt;/p&gt;

&lt;p&gt;Now I’m deep into the implementation when the realization hits: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Wait. I didn’t consider that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Maybe I made an assumption that was never actually supported. Maybe I just remembered something that was said last week. Maybe two requirements contradict each other. Whatever the cause, the result is the same: the solution no longer holds, a large portion of the code needs to be rewritten, and I’m already thinking about how I’m going to explain the delay. &lt;/p&gt;

&lt;p&gt;Without a doubt, this experience has been the single largest cause of frustration and stress over the course of my career. And based on my conversations with other developers, it's a very common one. The cause isn't a lack of aptitude, focus, or discipline. It's that I started building without a considered plan. The mistake, the missed dependency, the contradiction — they were always going to surface. The only question was when. And by discovering them at the end of a Friday, with the code already written, I've maximized their destructiveness.&lt;/p&gt;

&lt;p&gt;Things changed when I started hunting these problems down before writing any code. The contradiction or miss is still there, but caught in design, it never becomes a mistake, just a decision to make.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Time You Don't Think You Have
&lt;/h2&gt;

&lt;p&gt;I've worked in some extremely demanding environments. The work you're handed and the deadline attached to it are, more often than not, in open conflict — the ask underspecified, the timeline set before anyone understood the ask. In cultures like this, design reads as stalling. Time spent thinking is time stolen from actual work.  Questions are unwelcome, because every real one exposes &lt;strong&gt;complexity nobody wanted to admit was there&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Opening VS Code and typing feels like progress. Stepping back to think feels like stalling — worse, it feels like the thing you do when you're not sure what you're doing. &lt;/p&gt;

&lt;p&gt;But here's what those environments taught me: uncertainty and risk are unavoidable. We just get good at hiding them — from the people we report to, and from ourselves. It's a shell game. The people above you don't want to hear why something is hard, or impossible. You don't want to fail. So the unresolved questions get pushed to the back burner, until they boil over — at 4 p.m. on a Friday, in code you've already written, on the deadline you were protecting by not asking.&lt;/p&gt;

&lt;p&gt;Design and debugging are often the same problem-solving work performed at different times. That’s the thing about skipping design: the task doesn’t disappear. It moves, and it grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Wicked Problem
&lt;/h2&gt;

&lt;p&gt;By its nature, software development exceeds our ability to hold every rule, dependency, interaction, and unresolved question in our heads at once. It's been likened to a &lt;a href="https://en.wikipedia.org/wiki/Wicked_problem" rel="noopener noreferrer"&gt;wicked problem&lt;/a&gt;: our understanding of the solution changes as we attempt to solve it, and the solution itself exposes new constraints, contradictions, and unanswered questions. &lt;/p&gt;

&lt;p&gt;Over the course of my career, I’ve learned a few things to be consistently true:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nothing is as simple as it seems, no matter how confidently the project manager or product owner insists otherwise.&lt;/li&gt;
&lt;li&gt;Mistakes are inevitable. I will make unsupported assumptions, misunderstand requirements, reverse operands, and misspell variables. The people I depend on for crucial information will make mistakes too.&lt;/li&gt;
&lt;li&gt;A simple word, phrase, or concept can mean different things to different people (I recently sat through a standup discussion of what "send" vs "push" mean).&lt;/li&gt;
&lt;li&gt;Customers will change their minds. More often than not, people do not fully know what they want until they see an example of what they don't.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Software is therefore not simply constructed from a complete and stable set of requirements. The software itself becomes a proof of concept that users evaluate, reject, and refine. &lt;/p&gt;

&lt;p&gt;Once we accept this, design becomes more than deciding how to build a feature. It also becomes the process of identifying what might prevent the feature from working: conflicting requirements, hidden dependencies, unsupported assumptions, misunderstood language, and missing information.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Work of Design
&lt;/h2&gt;

&lt;p&gt;I've made the case that design catches problems early. But that's only one of its benefits. Even when nothing goes wrong — no contradiction, no missed dependency — designing first produces better software.&lt;/p&gt;

&lt;p&gt;That's because design is as much an analytical process as a diagnostic one. Working out which behaviors are needed and where they belong breaks one overwhelming problem into smaller, simpler ones. The design is where I think; the code is where I record what I decided. Skip the thinking and the code becomes the place I think — which is why it comes out tangled, reworked in place, shaped by whatever I understood the moment I typed each line rather than by the whole.&lt;/p&gt;

&lt;p&gt;It's also constructive. Intentionally designed code is easier to understand because it maps to how the problem actually decomposes. It's easier to fix, because a change has an obvious place to go. And it's easier to extend, because its structure is modeled on the real process it serves, rather than assembled from whatever shape the code happened to take as I wrote it. Let the structure emerge by accident and you get code that works only for the context it was written in, and resists attempts to change it later.&lt;/p&gt;

&lt;p&gt;Neither benefit here depends on catching defects. They're what you get from thinking about shape before shape is expensive to change. Problem-prevention is the same act seen from the other side — the roadblocks surface while you're deciding how the pieces fit, before any of it reaches code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problems Are the Product
&lt;/h2&gt;

&lt;p&gt;Unanticipated problems in software are inevitable. But they don't get in the way of the work, they &lt;strong&gt;are&lt;/strong&gt; the work: elegant design is just a hard problem handled well. Strip out the contradictions and the edge cases and there's nothing left to build, nothing to solve, nothing satisfying about having solved it. Finding those problems early and building them in — as features, not fixes — is the craft. The rest of this series is about finding and shaping those problems before they become disruptive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Power of Abstraction&lt;/strong&gt;: the implied skill needed to put DDD, Clean Architecture, and SOLID into practice&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behaviors and Interactions&lt;/strong&gt;: modeling responsibilities, interfaces, and the collaborations between them&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Just Enough Design&lt;/strong&gt;: a lightweight, iterative process for turning uncertainty into working software&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>oop</category>
      <category>design</category>
    </item>
    <item>
      <title>Expressive Design: Beyond Primitives</title>
      <dc:creator>Jim McKeon</dc:creator>
      <pubDate>Sun, 15 Mar 2026 02:22:21 +0000</pubDate>
      <link>https://dev.to/mckeondev/the-value-of-value-objects-28p8</link>
      <guid>https://dev.to/mckeondev/the-value-of-value-objects-28p8</guid>
      <description>&lt;p&gt;For years I’ve struggled with how to handle very simple validation scenarios.&lt;/p&gt;

&lt;p&gt;Most systems have identifiers with basic constraints — fixed length, allowed characters, or formatting rules. The problem usually isn’t writing the validation itself, but deciding &lt;strong&gt;where that validation should live&lt;/strong&gt; and ensuring it’s &lt;strong&gt;applied consistently&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Consider a simple example: suppose our application models an Order, and the system requires that an order ID must be exactly 10 characters long.&lt;/p&gt;

&lt;p&gt;For a long time I would have implemented it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing unusual there. Also, until fairly recently I would typically enforce validation using a separate validator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderValidator&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;ArgumentNullException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ThrowIfNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ThrowIfNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"Id must be 10 characters long"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now imagine a service responsible for creating orders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;OrderValidator&lt;/span&gt; &lt;span class="n"&gt;_validator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;OrderValidator&lt;/span&gt; &lt;span class="n"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_validator&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt; &lt;span class="nf"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;

        &lt;span class="n"&gt;_validator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// persist order, publish events, etc.&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Putting aside for the moment that using &lt;a href="https://enterprisecraftsmanship.com/posts/error-handling-exception-or-result/?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;exceptions for control flow&lt;/a&gt; isn’t ideal, this approach works, but it comes with a few undesirable side effects:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Any code responsible for creating or updating an Order needs to know that this validator exists.&lt;/li&gt;
&lt;li&gt; The rules for a valid order ID are disconnected from the value they describe.&lt;/li&gt;
&lt;li&gt; Invalid orders can exist until validation is explicitly invoked.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Also, what makes two orders equal in this case isn’t obvious. One possible fix is to implement equality directly on the Order entity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IEquatable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ReferenceEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;GetHashCode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetHashCode&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can compare orders using the Equals() method, but not with the == and != operators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Behold the Value Object
&lt;/h2&gt;

&lt;p&gt;Although I haven’t read the entire book (yet), I’m a big fan of Domain-Driven Design. One of its core concepts is the &lt;a href="https://martinfowler.com/bliki/ValueObject.html" rel="noopener noreferrer"&gt;Value Object&lt;/a&gt;. According to Eric Evans, a value object is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“An object that represents a descriptive aspect of the domain with no conceptual identity.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An easy way to think about value objects is that they behave like primitives such as string or int, but enforce business rules.&lt;/p&gt;

&lt;p&gt;In our example, we could introduce an OrderId type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;OrderId&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ThrowIfNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"Id must be 10 characters long"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;Value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Value&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the Order class becomes something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IEquatable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;OrderId&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ReferenceEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;GetHashCode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetHashCode&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now there's no need for an OrderValidator, and an Order &lt;strong&gt;can't be instantiated&lt;/strong&gt; with an invalid id. We can also add == and != operators so that orders compare naturally based on their Id.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Works
&lt;/h2&gt;

&lt;p&gt;By pushing validation into the type system, this approach yields a few practical benefits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No more duplicated validation rules&lt;/li&gt;
&lt;li&gt;Order identity is easy to find and understand because it's in one place&lt;/li&gt;
&lt;li&gt;The type system now clearly communicates intent: OrderId is no longer "just a string", it's a &lt;strong&gt;fundamental concept&lt;/strong&gt; like a DateTime or a class. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As more value objects are added, the application starts to resemble a self-contained, expressive framework rather than a collection of .NET primitives and utility methods.&lt;/p&gt;

&lt;p&gt;As a corollary to #3 above, I'm a huge proponent of DDD's concept of "Ubiquitous Language".  It forces everyone - project managers, subject matter experts, developers - to communicate in business-focused terms, rather than "tables" and "constraints" and "functions". There's many upsides to this approach, but the most consequential might be that it leads to fewer &lt;strong&gt;missed requirements&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Value objects are a small change in design, but they can have a huge impact. When rules are enforced by the type system, duplication disappears, invalid states become harder to create, and the application becomes easier to understand and navigate. Even simple value objects like OrderId can significantly improve the clarity and safety of a system.&lt;/p&gt;

&lt;p&gt;I’ve only scratched the surface of value objects here. In future posts, I’ll explore other practical techniques for writing software that’s easier to read, easier to reason about, and easier to change. If this topic interests you, I highly recommend &lt;em&gt;Implementing Domain-Driven Design&lt;/em&gt; by Vaughn Vernon, which explores these ideas in much greater depth.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>architecture</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
