<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="116850" data-post-id="116850">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="fireproofsocks" data-post="9" data-topic="20282">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fireproofsocks/48/7669_2.png" class="avatar"> fireproofsocks:</div>
<blockquote>
<p>In Go, as long as your class contains the proper methods, it will be considered as a viable implementation of an interface.</p>
</blockquote>
</aside>
<p>Want to have duck typing in Elixir?</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{module, data} = value 
new_value = module.some_function(value)
</code></pre>
<p>However if it is polymorphism you’re after, stick with <a href="https://elixir-lang.org/getting-started/protocols.html#protocols-and-structs" rel="nofollow">protocols</a> - even if you have to be explicit about implementing them.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="116850" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/functional-equivalent-of-oo-parent-child-code-sharing/20282/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-116850" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="116850"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="116853" data-post-id="116853">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="fireproofsocks" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fireproofsocks/120/7669_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  fireproofsocks
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The main drive in my thinking here is from having observed a large dev team bloat even simple applications into monolithic monstrosities.  Maintaining as much modularity and separation as possible has been one effective way to help confine the bloat: keep services/apps as small as possible.  In other words: if you can develop the functionality in <strong>one</strong> app in isolation and then use that component in a larger whole, that has generally equated to a win: faster dev/testing, and easier outsourcing and onboarding of devs.  That is really the primary motivation in attempting to avoid the dependency on the “parent” <code>OrderHandling</code> being referenced as a <code>@behaviour</code> in the various vendor modules.  Maybe attempting to obfuscate the relationship here is the wrong remedy to the problem.</p>
<p>Via dynamic dispatching, I can define a config value something like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">config :my_app, :vendor_dispatch_mapping, %{
  "vendor_one" =&gt; MyApp.VendorOne,
  "vendor_two" =&gt; MyApp.VendorTwo,
}
</code></pre>
<p>And then in my <code>OrderHandling</code> module I do a dynamic dispatch like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def dispatch_vendor_processing(vendor_id, order_data) do
    case Map.fetch(Application.get_env(:my_app, :vendor_dispatch_mapping), vendor_id) do
      {:ok, vendor_module} -&gt; vendor_module.process_order(order_data)
      :error -&gt; {:error, "Unmapped vendor"}
    end
end
</code></pre>
<p>I’m trying to think through how protocols might work here when the <code>OrderHandling</code> and <code>VendorOne</code> modules may be in separate applications and the OrderHandling may not yet know the implementation details…  I’m probably overthinking this.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="116853" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/functional-equivalent-of-oo-parent-child-code-sharing/20282/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-116853" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="116853"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="116865" data-post-id="116865">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="fireproofsocks" data-post="13" data-topic="20282">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fireproofsocks/48/7669_2.png" class="avatar"> fireproofsocks:</div>
<blockquote>
<p>The main drive in my thinking here is from having observed a large dev team bloat even simple applications into monolithic monstrosities. Maintaining as much modularity and separation as possible has been one effective way to help confine the bloat: keep services/apps as small as possible. In other words: if you can develop the functionality in <strong>one</strong> app in isolation and then use that component in a larger whole, that has generally equated to a win: faster dev/testing, and easier outsourcing and onboarding of devs. That is really the primary motivation in attempting to avoid the dependency on the “parent” <code>OrderHandling</code> being referenced as a <code>@behaviour</code> in the various vendor modules. Maybe attempting to obfuscate the relationship here is the wrong remedy to the problem.</p>
</blockquote>
</aside>
<p>That sounds <em>all</em> the more important to depend on OrderHandling!  You need to keep the API’s the same so you know how to call them, and they can program to those API’s so they know when they work or don’t, especially with tests against the API.  ^.^</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="116865" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/functional-equivalent-of-oo-parent-child-code-sharing/20282/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-116865" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="116865"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="116918" data-post-id="116918">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="opsb" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/opsb/120/5159_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  opsb
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>When you use inheritance to share code you still have to state the child/parent dependency. The fact is there <em>is</em> a dependency. I’m not sure what is to be gained or even how it could be possible to hide this fact (in OO or functional). If you simply want to avoid the function call sites in <code>VendorOne</code>/<code>VendorTwo</code> knowing about where the shared function lives then you could use</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule AppOne.VendorOne do
  import OrderHandling, only: [complex_function: 1]

  def do_something(foo, bar) do
    complex_function(foo)
  end
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="116918" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/functional-equivalent-of-oo-parent-child-code-sharing/20282/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-116918" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="116918"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="116919" data-post-id="116919">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>If you want to keep dependencies small then extract OrderHandling in it’s own package and make your main application as well as VendorOne and VendorTwo depend on it. If you no longer need OrderHandling you can easily scrap it from all three packages. Also your vendors don’t depend on your main application but they can still be used together based on the behaviour of OrderHandling.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="116919" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/functional-equivalent-of-oo-parent-child-code-sharing/20282/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-116919" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="116919"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>