<?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>Forem: Bertil Muth</title>
    <description>The latest articles on Forem by Bertil Muth (@bertilmuth).</description>
    <link>https://forem.com/bertilmuth</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F18887%2F0c162a88-a14c-432b-a5a4-2854acaca71e.jpg</url>
      <title>Forem: Bertil Muth</title>
      <link>https://forem.com/bertilmuth</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bertilmuth"/>
    <language>en</language>
    <item>
      <title>Review your requirements with AI</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Wed, 29 Nov 2023 15:03:36 +0000</pubDate>
      <link>https://forem.com/bertilmuth/review-your-requirements-with-ai-4jda</link>
      <guid>https://forem.com/bertilmuth/review-your-requirements-with-ai-4jda</guid>
      <description>&lt;p&gt;I created a GPT App that assists you in reviewing and improving your softare requirements. You can try it out here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.hood-group.com/en/ai-re-assistant"&gt;Requirements Assistant&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm looking forward to your feedback!&lt;/p&gt;

</description>
      <category>gpt4</category>
      <category>ai</category>
      <category>requirements</category>
    </item>
    <item>
      <title>Refactoring to Configurable Dependency in 5 Steps</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Thu, 18 Aug 2022 13:33:50 +0000</pubDate>
      <link>https://forem.com/bertilmuth/refactoring-to-configurable-dependency-in-5-steps-4fa8</link>
      <guid>https://forem.com/bertilmuth/refactoring-to-configurable-dependency-in-5-steps-4fa8</guid>
      <description>&lt;p&gt;&lt;a href="https://bertilmuth.medium.com/refactoring-to-configurable-dependency-in-5-steps-4b3077ac0e26?source=rss-a74297325869------2"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pgpnmB6o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2600/0%2ABDPeblYOSqBl5Vyf" alt="" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Configurable Dependency, a.k.a. Dependency Injection, is a pattern that enables you to switch dependencies of your application. The term…&lt;/p&gt;

&lt;p&gt;&lt;a href="https://bertilmuth.medium.com/refactoring-to-configurable-dependency-in-5-steps-4b3077ac0e26?source=rss-a74297325869------2"&gt;Continue reading on Medium »&lt;/a&gt;&lt;/p&gt;

</description>
      <category>hexagonalarchitectur</category>
      <category>programming</category>
      <category>cleanarchitecture</category>
      <category>dependencyinjection</category>
    </item>
    <item>
      <title>Act — a library for (hierarchical) state machines</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Thu, 09 Jun 2022 16:36:00 +0000</pubDate>
      <link>https://forem.com/bertilmuth/state-machine-library-5h7g</link>
      <guid>https://forem.com/bertilmuth/state-machine-library-5h7g</guid>
      <description>&lt;p&gt;I created a library for defining executable state machines in your code. This includes the possibility to define hierarchical state machines with sub states. State machines simplify understanding how your code works when you have complex business rules.&lt;/p&gt;

&lt;p&gt;As an oversimplified example for learning purposes, look at the following state machine for a shopping cart.&lt;/p&gt;

&lt;p&gt;It represents its two fundamental states of being either empty, or non-empty.&lt;/p&gt;

&lt;p&gt;The AddItem trigger causes a change to the non-empty cart state.&lt;/p&gt;

&lt;p&gt;The RemoveItem trigger causes a change to the empty cart state, if the cart only contains 1 item.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvkeo5ktbeuxosyi8yhv2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvkeo5ktbeuxosyi8yhv2.png" alt="Image of a statemachine of a shopping cart, with two states" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here's how the state machine is presented in code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Cart&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Trigger&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;emptyCartState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Empty Cart"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Cart&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Trigger&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;nonEmptyCartState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Non-Empty Cart"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="nc"&gt;Statemachine&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Cart&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Trigger&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;statemachine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Statemachine&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;builder&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;states&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;emptyCartState&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;nonEmptyCartState&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;transitions&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;transition&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;anyState&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;nonEmptyCartState&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; 
            &lt;span class="n"&gt;when&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AddItem&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;consumeWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Cart:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;addItem&lt;/span&gt;&lt;span class="o"&gt;))),&lt;/span&gt;

        &lt;span class="n"&gt;transition&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nonEmptyCartState&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonEmptyCartState&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; 
            &lt;span class="n"&gt;whenInCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;RemoveItem&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;supplyWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Cart:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;removeItem&lt;/span&gt;&lt;span class="o"&gt;))),&lt;/span&gt;

        &lt;span class="n"&gt;transition&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nonEmptyCartState&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;emptyCartState&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; 
            &lt;span class="n"&gt;whenInCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;RemoveItem&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;supplyWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Cart:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;removeItem&lt;/span&gt;&lt;span class="o"&gt;)))&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flows&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;entryFlow&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;when&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CreateCart&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Cart:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;createCart&lt;/span&gt;&lt;span class="o"&gt;)))&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please visit the &lt;a href="https://github.com/bertilmuth/act/"&gt;project on GitHub&lt;/a&gt; for details. I'm looking forward to your feedback.&lt;/p&gt;

</description>
      <category>java</category>
      <category>statemachine</category>
      <category>bdd</category>
      <category>eventdriven</category>
    </item>
    <item>
      <title>Developer-friendly event sourcing</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Sat, 15 Jan 2022 13:54:38 +0000</pubDate>
      <link>https://forem.com/bertilmuth/developer-friendly-event-sourcing-23ga</link>
      <guid>https://forem.com/bertilmuth/developer-friendly-event-sourcing-23ga</guid>
      <description>&lt;p&gt;Here's what event sourcing is about: Every time you make a change to the application state, you record the change as an event.&lt;br&gt;
You can replay the events since the beginning of the recording, up to a certain time. Then you've recreated the state of the application at that time. And by merging the events into a different data structure, you can provide a user specific view of the state (a "query model").&lt;/p&gt;

&lt;p&gt;In short, event sourcing is about persisting events instead of just the current state. Event sourcing can be helpful for auditing purposes, and to analyze or rebuild previous system states for business analysis. &lt;/p&gt;

&lt;p&gt;Think of a shopping cart: a typical e-commerce application would only store the state of the cart when the user proceeds to checkout. What if you want to know which shopping cart items have been removed by the user, to optimize the purchasing flow? That's when storing each event becomes helpful, e.g. &lt;em&gt;ShoppingCartItemRemoved&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  A Hello World example
&lt;/h2&gt;

&lt;p&gt;In this example, a user sends a POST HTTP request with the data of a &lt;em&gt;CreateGreeting&lt;/em&gt; command to the backend. This command contains the name of the person to greet. The backend transforms the command into a &lt;em&gt;GreetingCreated&lt;/em&gt; event. This event contains the person's name from the command, and a default salutation (&lt;em&gt;Hello,&lt;/em&gt;):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnwjsupcxesbrk288j279.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnwjsupcxesbrk288j279.PNG" alt="As a summary, a CreateGreeting command with person name Jill is consumed by the Greeting entity that handles the command and produces the GreetingCreated event with salutation hello and person name Jill" width="800" height="205"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The event also contains the id of the entity you see in the middle: the &lt;code&gt;Greeting&lt;/code&gt; entity that consumes the commands, and produces the events. That way, the state of this entity can later be reconstructed.&lt;/p&gt;

&lt;p&gt;By producing the event, the &lt;code&gt;Greeting&lt;/code&gt; entity has accepted the command as valid, and the event records this as a fact. The event is now stored in a journal, e.g. an in-memory, relational or NoSQL database.&lt;/p&gt;

&lt;p&gt;So far, the state of the &lt;code&gt;Greeting&lt;/code&gt; entity hasn't changed yet.&lt;br&gt;
To change the state, &lt;code&gt;Greeting&lt;/code&gt; takes the event and current state as input, and produces a new instance of the state class:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuiy6jr5ipknxjpz5vqy6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuiy6jr5ipknxjpz5vqy6.png" alt="As a summary, a GreetingCreated event with salutation hello and person name Jill is consumed by the Greeting entity that handles the event and produces a new GreetingState instance with salutation hello and person name Jill" width="800" height="227"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Objects of &lt;code&gt;GreetingState&lt;/code&gt; are immutable. &lt;code&gt;Greeting&lt;/code&gt; replaces the old state with the new state after applying the event.&lt;/p&gt;

&lt;p&gt;What if you want to change the salutation for Jill's greeting later on? This can be done with a &lt;code&gt;ChangeSalutation&lt;/code&gt;command. If you encode the id of Jill's &lt;code&gt;Greeting&lt;/code&gt; entity in the request URL, the command handling looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa5sc976cdgdy3ff8cing.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa5sc976cdgdy3ff8cing.PNG" alt="A ChangeSalutation command with salutation Howdy is consumed by the Greeting entity that handles the command, and produces the SalutationChanged event with salutation Howdy" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that the event captures only the information that is relevant for the change about to happen. It doesn't need to capture all information in &lt;code&gt;GreetingState&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Applying the &lt;code&gt;SalutationChanged&lt;/code&gt; event looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ujrmctd31vcdlebtejz.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ujrmctd31vcdlebtejz.PNG" alt="The SalutationChanged event with salutation Howdy is consumed by the Greeting entity that handles the event and produces a new GreetingState instance with salutation Howdy and person name Jill as output" width="800" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The interesting thing is this: &lt;code&gt;Greeting&lt;/code&gt; takes the salutation from the event, and combines it with the &lt;code&gt;personName&lt;/code&gt; from its current state, to produce the new state.&lt;/p&gt;
&lt;h2&gt;
  
  
  The implementation problem
&lt;/h2&gt;

&lt;p&gt;The problem I've seen in this. When building an event-sourced application, there is a steep learning curve. Not only do you need to get adjusted to this new way of thinking about state. You also need to learn the event sourcing library/framework details.&lt;/p&gt;

&lt;p&gt;I want to change that. I created the Being library. It aims to cut down the technical complexity as far as possible. You can find it on &lt;a href="https://github.com/bertilmuth/being"&gt;Github&lt;/a&gt;. It's in an early stage of development, so I'm very thankful for Feedback.&lt;/p&gt;
&lt;h2&gt;
  
  
  Command and event handling code
&lt;/h2&gt;

&lt;p&gt;When you use Being, you need to define the command handlers: which types of commands the entity consumes, and which event(s) it produces as a reaction to each command.&lt;/p&gt;

&lt;p&gt;You also need to define the event handlers: for each of the event types, which new entity state to create as a reaction to it.&lt;/p&gt;

&lt;p&gt;The behavior of the &lt;code&gt;Greeting&lt;/code&gt; entity shown below has the following &lt;a href="https://github.com/bertilmuth/being-samples/blob/main/greetings/src/main/java/org/requirementsascode/being/samples/greeting/model/Greeting.java"&gt;code&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Greeting&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;AggregateBehavior&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GreetingCommand&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;GreetingState&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;GreetingState&lt;/span&gt; &lt;span class="nf"&gt;initialState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;GreetingState&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;identifiedBy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;CommandHandlers&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GreetingCommand&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;GreetingState&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;commandHandlers&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;CommandHandlers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;handle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;commandsOf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CreateGreeting&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GreetingCreated&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Hello,"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;)),&lt;/span&gt;
            &lt;span class="n"&gt;commandsOf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ChangeSalutation&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SalutationChanged&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;EventHandlers&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GreetingState&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;eventHandlers&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;EventHandlers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;handle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;eventsOf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;GreetingCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GreetingState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;)),&lt;/span&gt;
            &lt;span class="n"&gt;eventsOf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SalutationChanged&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GreetingState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apart from the &lt;code&gt;initialState()&lt;/code&gt; method that defines the starting state of &lt;code&gt;Greeting&lt;/code&gt;, this should look pretty familiar.&lt;/p&gt;

&lt;p&gt;The first command handler consumes a &lt;code&gt;CreateGreeting&lt;/code&gt; command that contains the name of the person to greet, and produces a &lt;code&gt;GreetingCreated&lt;/code&gt; event. &lt;/p&gt;

&lt;p&gt;But a user can also change the salutation via a &lt;code&gt;ChangeSalutation&lt;/code&gt; command. This command contains only the new text for the salutation, not the person's name. The person is identified by the entity's id, &lt;code&gt;state.id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Both the command handlers and the event handlers can use the current state of the entity. So when a &lt;code&gt;SalutationChanged&lt;/code&gt; event is applied, the person name is not taken from the event, but from the current state of the entity: &lt;code&gt;(event,state) -&amp;gt; new GreetingState(event.id, event.salutation, state.personName)&lt;/code&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Code for the Greeting entity's state
&lt;/h2&gt;

&lt;p&gt;Here's the code for the &lt;code&gt;GreetingState&lt;/code&gt; class that represents the state of the entity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GreetingState&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;GreetingState&lt;/span&gt; &lt;span class="nf"&gt;identifiedBy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;GreetingState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;GreetingState&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;salutation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;personName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"GreetingState [id="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", salutation="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;salutation&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", personName="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"]"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// hashCode() and equals() omitted for brevity&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, objects of the state class are immutable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code for commands and events
&lt;/h2&gt;

&lt;p&gt;Commands are simple POJOs, as you can see in the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreateGreeting&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;GreetingCommand&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;CreateGreeting&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;personName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"CreateGreeting [personName="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"]"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Commands of an entity implement a common interface, like &lt;code&gt;GreetingCommand&lt;/code&gt; in the example, which may be empty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;GreetingCommand&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason for having a common interface for the commands is type safety. Use this command interface as the first type parameter of the entity class, as shown above.&lt;/p&gt;

&lt;p&gt;Each event class must be a subclass of &lt;code&gt;IdentifiedDomainEvent&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GreetingCreated&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;IdentifiedDomainEvent&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;GreetingCreated&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SemanticVersion&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"1.0.0"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;toValue&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;salutation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;salutation&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;personName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;identity&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&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="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"GreetingCreated [id="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", salutation="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;salutation&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", personName="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;personName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"]"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Being is based on the powerful &lt;a href="https://docs.vlingo.io/"&gt;VLINGO XOOM&lt;/a&gt; platform that defines the &lt;code&gt;IdentifiedDomainEvent&lt;/code&gt; super class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Apart from what I've shown above, you also need to define the HTTP request handlers. The &lt;a href="https://github.com/bertilmuth/being"&gt;Being&lt;/a&gt; website explains how to do that.&lt;/p&gt;

&lt;p&gt;I want to invite you to have a look at it, if you find this topic interesting. And I'm very grateful for feedback.&lt;br&gt;
Drop a note in the comments, visit the &lt;a href="https://gitter.im/requirementsascode/community"&gt;Gitter community&lt;/a&gt; or contact &lt;a href="https://twitter.com/BertilMuth"&gt;me&lt;/a&gt; on Twitter.&lt;/p&gt;

</description>
      <category>java</category>
      <category>eventdriven</category>
      <category>eventsourcing</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Time to follow back</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Sun, 07 Nov 2021 17:03:25 +0000</pubDate>
      <link>https://forem.com/bertilmuth/time-to-follow-back-ff7</link>
      <guid>https://forem.com/bertilmuth/time-to-follow-back-ff7</guid>
      <description>&lt;p&gt;I noticed it on Twitter first: I became increasingly bored by the content I was seeing. I also noticed the almost cultish appraisal of “thought leaders”. Sure, some of them are great minds and post interesting stuff. But overall I found much of it trivial. And some responses were outright arrogant.&lt;/p&gt;

&lt;p&gt;I suspect much of what happens on social media is based on popularity and social group phenomena, rather than quality of content. And I have probably missed a lot of interesting ideas because I followed the “big names” instead of giving everybody a fair chance.&lt;/p&gt;

&lt;p&gt;So I’m ready for an experiment. At the time of this writing, I have close to 3100 followers on dev.to. But I only follow around 50 people. Shame on me ;-)&lt;/p&gt;

&lt;p&gt;In the next couple of days, I will follow everyone who follows me back - all the existing followers, and new followers. Let’s see how that goes.&lt;/p&gt;

&lt;p&gt;What do you think about all of this?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>The most interesting topic</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Sun, 31 Oct 2021 12:52:56 +0000</pubDate>
      <link>https://forem.com/bertilmuth/the-most-interesting-topic-4ck8</link>
      <guid>https://forem.com/bertilmuth/the-most-interesting-topic-4ck8</guid>
      <description>&lt;p&gt;What’s the most interesting topic you’re learning about at the moment, tech or otherwise?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>A laser-sharp analysis of the dysfunctions in large scale organizations</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Thu, 30 Sep 2021 12:37:49 +0000</pubDate>
      <link>https://forem.com/bertilmuth/a-laser-sharp-analysis-of-the-dysfunctions-in-large-scale-organizations-4ffo</link>
      <guid>https://forem.com/bertilmuth/a-laser-sharp-analysis-of-the-dysfunctions-in-large-scale-organizations-4ffo</guid>
      <description>&lt;p&gt;I recently posted this question on Twitter:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1443239158475108367-752" src="https://platform.twitter.com/embed/Tweet.html?id=1443239158475108367"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1443239158475108367-752');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1443239158475108367&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;My friend Daniel answered:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1443264870938517507-246" src="https://platform.twitter.com/embed/Tweet.html?id=1443264870938517507"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1443264870938517507-246');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1443264870938517507&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;I didn’t see that one coming. Okay…&lt;br&gt;
I’ve been working as an Agile Coach, Scrum Master, consultant and trainer for large organizations like banks, insurances, automotive companies, medical device manufacturers and software development houses. I’ve seen the same dysfunctional patterns repeat over and over again. So I surely have an opinion on that. Is my analysis laser-sharp? Well, you decide.&lt;/p&gt;

&lt;h2&gt;
  
  
  The machine metaphor
&lt;/h2&gt;

&lt;p&gt;We need to go way back in history to understand what happens in organizations today. Up to the first part of the 19th century, development of products was mainly done by craftsmen. Products were tailor made for the customers. Markets were mostly local.&lt;/p&gt;

&lt;p&gt;The game changed with the industrialization. A different problem needed to be solved. Instead of tailoring a product for the individual customer, the question became: How do we produce the same product in large numbers? How do we ensure an acceptable quality, efficient and at low cost? How do we conquer new markets, once a market gets saturated?&lt;/p&gt;

&lt;p&gt;The most important technical innovation that made a solution possible was the assembly line. Companies could now hire uneducated workers at low cost. All they needed to do was teach the workers how to play their part. Every employee working at the line was supposed to repeat the same kind of actions over and over again. &lt;/p&gt;

&lt;p&gt;In a way, those employees acted like parts of a machine. And like parts of a machine, they were considered replaceable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu392plgu1swkinki8nvk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu392plgu1swkinki8nvk.jpg" alt="Spitfire manufacture. WWII World War 2 Castle Bromwich Aeroplane Factory, Birmingham 1940-46. Manufacturers: Vickers Armstrong" width="800" height="519"&gt;&lt;/a&gt;Spitfire manufacture. WWII World War 2 Castle Bromwich Aeroplane Factory, Birmingham 1940-46. Manufacturers: Vickers Armstrong. On &lt;a href="https://unsplash.com/photos/XJ-N7eLTOhk"&gt;Unsplash&lt;/a&gt;. &lt;br&gt;
But there needed to be someone overseeing production. Someone with more knowledge. Who could make the right decisions when something went wrong. That's how 20th century management was born.&lt;/p&gt;

&lt;p&gt;The job of the managers was to control that the machine was working in order. Issue a command if necessary. And control the output. The managers were the users of the machine.&lt;/p&gt;

&lt;p&gt;The machine metaphor as an explanation of how the world works had been around in science and philosophy &lt;a href="https://bsahely.com/2018/12/30/the-rise-and-fall-of-the-machine-metaphor-organizational-similarities-and-differences-between-machines-and-living-beings-by-victor-marques-carlos-brito/"&gt;long before&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But now, it also started shaping how people thought about product development. And it has been ever since. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The machine metaphor is ubiquitous. We can hear it in&lt;br&gt;
everyday speech: “things are humming,” “well-oiled,” “on&lt;br&gt;
autopilot,” “firing on all cylinders,” “re-engineering,” and&lt;br&gt;
“I’m just a cog in the wheel.” Viewing an organization as a&lt;br&gt;
machine shapes our perceptions, expectations, and actions&lt;br&gt;
profoundly.&lt;br&gt;
&lt;a href="https://www.acgme.org/globalassets/PDFs/Symposium/Suchman_Organizations-as-Machines.pdf"&gt;Organizations as Machines, Organizations as Conversations&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I will highlight three typical dysfunctions that result from it next. &lt;/p&gt;

&lt;h2&gt;
  
  
  Dysfunction #1: Command &amp;amp; Control
&lt;/h2&gt;

&lt;p&gt;The idea that it makes sense for a manager to control the work and assign tasks to workers relies on the following assumptions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The manager has an overview of the situation&lt;/li&gt;
&lt;li&gt;The manager has more knowledge than the worker doing the job, concerning the task&lt;/li&gt;
&lt;li&gt;The task can be assigned to a single individual&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These assumptions were fulfilled in industrial production. They may still be useful in restaurant kitchens. But they can hardly be applied to knowledge work. &lt;/p&gt;

&lt;p&gt;For innovative products, software development requires a whole group of creative people to exchange ideas. This is the best way to solve unknown problems that exceed the capabilities of a single individual that humanity knows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dysfunction #2: Optimizing utilization
&lt;/h2&gt;

&lt;p&gt;At the assembly line, optimizing utilization of individual workers led to an optimization of the overall throughput of the system. Likewise, in many organizations today, employees work on multiple tasks or even projects at the same time. Yet the hope that a utilization close to 100% will lead to maximum productivity is often in vain.&lt;/p&gt;

&lt;p&gt;Counterintuitively, the linear relationship between utilization and productivity doesn't hold up in environments with high variability in the arrival rate and size of work items. Note that this isn't my personal opinion. You can prove it mathematically, using queuing theory.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is not the case that everything goes fast and smooth on the highway until just before 100 percent capacity of cars on the road. Rather, things slow down and gridlock happens well before capacity is reached.&lt;br&gt;
[...]&lt;br&gt;
With the misunderstanding “delay only starts when the highway is 100 percent full, ” there is a misguided focus on trying to improve cycle time by increasing resource utilization—getting the people in product development to be more busy, usually by more multitasking. This is the local-optimization thinking mistake.&lt;br&gt;
[...]&lt;br&gt;
As utilization goes up in a system with lots of variability, average cycle time gets worse, not better. &lt;br&gt;
&lt;a href="https://less.works/less/principles/queueing_theory"&gt;Large Scale Scrum on Queuing Theory&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Dysfunction #3: Single function silos
&lt;/h2&gt;

&lt;p&gt;Knowledge silos can't be avoided in large scale organizations. Due to the many possible communication relationships, each employee only communicates with a limited number of his colleagues. Software architecture styles like microservices even promote the reduction of dependencies between teams as a key benefit.&lt;/p&gt;

&lt;p&gt;Yet there is a problem with how organizations set up these silos. Assembly line workers repeated the same activities over and over again. Departments in organizations follow that model: they have a single function. The QA department, the IT department, the Business Analysts etc. &lt;/p&gt;

&lt;p&gt;Do one thing, and do it well. What has worked for the &lt;a href="https://techcrunch.com/2009/08/21/do-one-thing-and-do-it-well-40-years-of-unix/"&gt;UNIX philosophy&lt;/a&gt; became a problem for departments that needed to cooperate to make any progress with the product they built together. &lt;/p&gt;

&lt;p&gt;The consequences are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;delays when exchanging information&lt;/li&gt;
&lt;li&gt;local optimization based on department specific goals&lt;/li&gt;
&lt;li&gt;individual bonus systems that stand in the way of overall progress&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I have highlighted three dysfunctions of large scale organizations. There are many more. But even after 18 years in the industry, I still believe there's a lot we can do about it. And we need to have patience. There's a lot of unlearning and learning that needs to happen. &lt;/p&gt;

&lt;p&gt;Let us build a better, more inclusive and sustainable future together. Inside and outside of tech. &lt;/p&gt;

&lt;p&gt;And one final remark: are you happy now, Daniel ;-) ?&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>discuss</category>
      <category>motivation</category>
      <category>agile</category>
    </item>
    <item>
      <title>Hello world, modular monolith</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Fri, 27 Aug 2021 06:43:26 +0000</pubDate>
      <link>https://forem.com/bertilmuth/hello-world-modular-monolith-2pmm</link>
      <guid>https://forem.com/bertilmuth/hello-world-modular-monolith-2pmm</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2ABfpItx9bAUC7CS_5" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2ABfpItx9bAUC7CS_5"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@kaleidico?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Kaleidico&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I just published a new side project of mine, for creating modular monoliths.&lt;/p&gt;

&lt;p&gt;It’s very early stage. Not more than an outline. I’m curious what you think about it, please leave me a note in the comments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/bertilmuth/modular-monolith-helloworld" rel="noopener noreferrer"&gt;GitHub - bertilmuth/modular-monolith-helloworld: A hello world style example of a producer and consumer communicating with an event bus.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each module is contained in its own Gradle project. Apart from main and connector, the modules have no dependencies.&lt;/p&gt;

&lt;p&gt;This modular style of development potentially has the following benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The modules mark &lt;em&gt;team boundaries&lt;/em&gt;. Each team can work on its own data and behavior, hardly affected by the work of other teams. That can reduce the time to market of development teams.&lt;/li&gt;
&lt;li&gt;Isolating the modules &lt;em&gt;reduces cognitive load&lt;/em&gt;. A developer no longer needs to understand the whole application, but only the module she works on.&lt;/li&gt;
&lt;li&gt;Reducing the dependencies avoids the dreaded &lt;em&gt;big ball of mud&lt;/em&gt;, and makes the application in general more maintainable. In particular, it avoids cyclic dependencies between parts of the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This modular style has the following downsides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It leads to &lt;em&gt;eventual consistency&lt;/em&gt;. Since the modules communicate asynchronously, there is no guarantee for immediate consistency of data between modules.&lt;/li&gt;
&lt;li&gt;More effort for &lt;em&gt;reliable messaging&lt;/em&gt;. In a real world application, it must be made sure that no events get lost. This complicates the infrastructure logic.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>technology</category>
      <category>spring</category>
      <category>springboot</category>
      <category>java</category>
    </item>
    <item>
      <title>Have you built a modular monolith?</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Tue, 24 Aug 2021 11:55:36 +0000</pubDate>
      <link>https://forem.com/bertilmuth/have-you-built-a-modular-monolith-4ll4</link>
      <guid>https://forem.com/bertilmuth/have-you-built-a-modular-monolith-4ll4</guid>
      <description>&lt;p&gt;Anybody has built a modular monolith?  If yes: what were the design principles you used (i.e. request/response via interfaces, events on an in memory event bus for decoupling etc.)?&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Dependency Injection in Javascript for Beginners</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Thu, 19 Aug 2021 14:51:43 +0000</pubDate>
      <link>https://forem.com/bertilmuth/dependency-injection-in-javascript-for-beginners-5b0d</link>
      <guid>https://forem.com/bertilmuth/dependency-injection-in-javascript-for-beginners-5b0d</guid>
      <description>&lt;p&gt;A few days ago, one of my students showed me his code. He had written an AWS lambda function that scrapes a web site and posts contents to Discord. He was unhappy because he couldn't test the contents of the messages being posted. He said that there wasn't a mocking framework for the external services.&lt;/p&gt;

&lt;p&gt;I told him that he doesn't need a mocking framework. He just needs to use Dependency Injection (DI). DI enables you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;test business logic isolated from external services and frameworks&lt;/li&gt;
&lt;li&gt;switch services, technologies and frameworks more easily&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dependency Injection is at the heart of architectural styles like &lt;a href="https://medium.com/javarevisited/modern-clean-architecture-c1765f8f3fc1"&gt;Clean Architecture&lt;/a&gt; and &lt;a href="https://dev.to/bertilmuth/implementing-a-hexagonal-architecture-1kgf"&gt;Hexagonal Architecture&lt;/a&gt;. Yet, you hardly find any simple examples that address DI specifically.&lt;/p&gt;

&lt;p&gt;In this article, I will walk you through a simple example. Think of a calculator that adds and subtracts numbers and prints the results to the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&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;This is what the code prints to the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8
99
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt; functions &lt;em&gt;know&lt;/em&gt; the &lt;code&gt;log&lt;/code&gt; function. Calculation and console logging are &lt;em&gt;tightly coupled&lt;/em&gt;.  &lt;/p&gt;

&lt;p&gt;Think about that for a minute. What's the problem?&lt;/p&gt;

&lt;p&gt;If you want to display the result on some other output channel, i.e. the GUI, you need to adapt the functions. The more output channels, the more complicated the functions become. Even though their main purpose is to calculate the result.&lt;/p&gt;

&lt;p&gt;In your tests, you don't even want to print to the console. It only makes your tests slow. You just want to know if the result of the mathematical operation is correct.&lt;/p&gt;

&lt;p&gt;So what can you do about it? How does DI help in the example?&lt;/p&gt;

&lt;p&gt;You need to move the knowledge about the concrete display function out of &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt;. The simplest way to do that is to pass it as an argument. Here's the same example, but using DI. The output is the same as above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&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;You pass in the &lt;code&gt;log&lt;/code&gt; function as an argument to &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt;. These functions then call &lt;code&gt;log&lt;/code&gt; by using &lt;code&gt;display&lt;/code&gt;, like an alias. So in this code, &lt;code&gt;display(result);&lt;/code&gt; is equivalent to &lt;code&gt;log(result);&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt; no longer know the exact function for displaying, you can pass in other functions. Say that on top of logging, you want to show an alert to the user in the GUI. Here's the code for that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&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;We don't need to write code for &lt;code&gt;alert&lt;/code&gt;. It's a built in Javascript function.&lt;/p&gt;

&lt;p&gt;Finally, how do you approach testing? I'm not going into details of a testing framework. But here's the idea how to test with DI.&lt;/p&gt;

&lt;p&gt;Using DI, you can pass in any function. It doesn't &lt;em&gt;have to&lt;/em&gt; display. It can check whether the result is correct instead.&lt;br&gt;
So here's a call that shows whether the result of 5 plus 3 equals 8:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code passes an &lt;em&gt;anonymous function&lt;/em&gt; as third argument. Also known as a &lt;em&gt;lambda function&lt;/em&gt;. It could have been a named function instead - that doesn't matter. &lt;/p&gt;

&lt;p&gt;The point is: instead of displaying anything, the function takes the result of &lt;code&gt;add&lt;/code&gt; and shows an alert whether it is equal to 8.&lt;/p&gt;

&lt;p&gt;In a real world application, the next steps would be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move the functions that call I/O, external services etc. to a separate file&lt;/li&gt;
&lt;li&gt;Establish a single place where all dependencies to I/O, external services etc. are created&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, you can switch these dependencies. For testing, or in your production code. And that's a simple way to do dependency injection in Javascript.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Modern Clean Architecture</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Tue, 10 Aug 2021 15:55:32 +0000</pubDate>
      <link>https://forem.com/bertilmuth/modern-clean-architecture-5gla</link>
      <guid>https://forem.com/bertilmuth/modern-clean-architecture-5gla</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2qaznwl72ehdsebe5qn1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2qaznwl72ehdsebe5qn1.jpg" alt="Guggenheim Museum in New York" width="300" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html"&gt;Clean Architecture&lt;/a&gt; is a term coined by Robert C. Martin. The main idea: Entities and use cases are independent of frameworks, UI, the database and external services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://bertilmuth.medium.com/modern-clean-architecture-c1765f8f3fc1?source=rss-a74297325869------2"&gt;Continue reading on Medium (paywall free) »&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>cleanarchitecture</category>
      <category>spring</category>
      <category>technology</category>
    </item>
    <item>
      <title>Modern clean architecture</title>
      <dc:creator>Bertil Muth</dc:creator>
      <pubDate>Fri, 06 Aug 2021 19:28:30 +0000</pubDate>
      <link>https://forem.com/bertilmuth/modern-clean-architecture-2dj0</link>
      <guid>https://forem.com/bertilmuth/modern-clean-architecture-2dj0</guid>
      <description>&lt;p&gt;I am pleased to announce the release of the &lt;a href="https://github.com/bertilmuth/modern-clean-architecture"&gt;modern-clean-architecture&lt;/a&gt; project.&lt;/p&gt;

&lt;p&gt;Clean architecture follows these principles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The domain code and use cases of an application are independent of frameworks, UI, the database or any external agency, e.g. external services.&lt;/li&gt;
&lt;li&gt;Through this clear separation of concern, the domain code and use cases become testable independent of the framework, UI or infrastructure.&lt;/li&gt;
&lt;li&gt;The user interface, database technology, external services and framework specific code can change without affecting the domain code and vice versa.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Modern clean architecture provides a fresh view on clean architecture, in a Spring Boot environment. It reduces the effort required to create a clean architecture through the following constraints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Serialization of immutable requests and responses&lt;/strong&gt; without serialization specific annotations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No necessity for DTOs&lt;/strong&gt;. You can use the same immutable value objects for requests/responses in web layer and use cases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generic endpoint&lt;/strong&gt; that receives and forwards POST requests. New behavior and domain logic can be added and used without the need to write framework specific code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing with a repository double&lt;/strong&gt; that acts like a normal repository. No need for mocking it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Visit the &lt;a href="https://github.com/bertilmuth/modern-clean-architecture"&gt;website&lt;/a&gt;, I'm happy to hear your thoughts. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
