Skip to content

Commit 8fb0f81

Browse files
committed
Prepare article for publication
1 parent e9dca88 commit 8fb0f81

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

_posts/2024-09-11-dependency-inversion-without-inversion-of-control.html _posts/2025-01-27-dependency-inversion-without-inversion-of-control.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: post
33
title: "Dependency inversion without inversion of control"
44
description: "Here, have a sandwich."
5-
date: 2024-09-11 19:05 UTC
5+
date: 2025-01-27 13:02 UTC
66
tags: [Dependency Injection, Architecture]
77
image: "/content/binary/dip-ioc-venn.png"
88
image_alt: "Venn diagram with DIP to the left and IoC to the right. The intersection is substantial, but not overwhelming."
@@ -23,7 +23,7 @@
2323
<img src="/content/binary/dip-ioc-venn.png" alt="Venn diagram with DIP to the left and IoC to the right. The intersection is substantial, but not overwhelming.">
2424
</p>
2525
<p>
26-
This figure suggests that the sets are of equal size, which doesn't have to be the case. The point, rather, is that while the intersection may be substantial, each <a href="https://en.wikipedia.org/wiki/Complement_(set_theory)">complement</a> is not only not empty, but richly populated.
26+
This figure suggests that the sets are of equal size, which doesn't have to be the case. The point, rather, is that while the intersection may be substantial, each <a href="https://en.wikipedia.org/wiki/Complement_(set_theory)">relative complement</a> is not only not empty, but richly populated.
2727
</p>
2828
<p>
2929
In this article, I'm not going to spend more time on the complement IoC without DIP. Rather, I'll expand on how to apply the DIP without IoC.
@@ -63,13 +63,13 @@ <h3 id="a51dd63df2474002b81bee601c86eb8d">
6363
<footer><cite><a href="https://x.com/unclebobmartin/status/1817263979774816379">Tweet</a>, Robert C. Martin</cite></footer>
6464
</blockquote>
6565
<p>
66-
While this was the answer I'd hoped for, it's easy dismiss this exchange as an <a href="https://en.wikipedia.org/wiki/Argument_from_authority">appeal to authority</a>. On the other hand, as Carl Sagan said, "If you wish to make an apple pie from scratch, you must first invent the universe," which obviously isn't practical, and so we instead <a href="https://en.wikipedia.org/wiki/Standing_on_the_shoulders_of_giants">stand on the shoulders of giants</a>.
66+
While this was the answer I'd hoped for, it's easy to dismiss this exchange as an <a href="https://en.wikipedia.org/wiki/Argument_from_authority">appeal to authority</a>. On the other hand, as Carl Sagan said, "If you wish to make an apple pie from scratch, you must first invent the universe," which obviously isn't practical, and so we instead <a href="https://en.wikipedia.org/wiki/Standing_on_the_shoulders_of_giants">stand on the shoulders of giants</a>.
6767
</p>
6868
<p>
6969
In this context, asking Robert C. Martin was relevant because he's the original author of works that introduce the DIP. It's reasonable to assume that he has relevant insights on the topic.
7070
</p>
7171
<p>
72-
It's not that I can't argue my case independently, but rather that I didn't think that the comments section of a Stack Overflow question was the right place to do so. This blog, on the other hand, is mine, and I can use all the words I'd like, so I'll now proceed to do so.
72+
It's not that I can't argue my case independently, but rather that I didn't think that the comments section of a Stack Overflow question was the right place to do that. This blog, on the other hand, is mine, I can use all the words I'd like, and I'll now proceed to do so.
7373
</p>
7474
<h3 id="bfe353d609ea45e48ffb0efe939f4c01">
7575
Kernel of the idea <a href="#bfe353d609ea45e48ffb0efe939f4c01">#</a>
@@ -96,10 +96,10 @@ <h3 id="bfe353d609ea45e48ffb0efe939f4c01">
9696
<p>
9797
"Abstraction is <em>the elimination of the irrelevant and the amplification of the essential.</em>"
9898
</p>
99-
<footer><cite><a href="/ref/doocautbm">Designing Object-Oriented C++ Applications Using The Booch Method</a>, Robert C. Martin, his emphasis</cite></footer>
99+
<footer><cite><a href="/ref/doocautbm">Designing Object-Oriented C++ Applications Using The Booch Method</a>, ch. 00, Robert C. Martin, his emphasis</cite></footer>
100100
</blockquote>
101101
<p>
102-
The same connotation of <em>abstraction</em> seems to apply to the definition of the DIP. If, for example, we imagine that we consider a Domain Model, the business logic, as the essential we'd like to amplify, we may rightfully consider a particular persistence mechanism a detail. Even more concretely, if you want to take restaurant reservations via a <a href="https://en.wikipedia.org/wiki/REST">REST</a> API, the <a href="/2020/01/27/the-maitre-d-kata">business rules that determine whether or not you can accept a reservation</a> shouldn't depend on a particular database technology.
102+
The same connotation of <em>abstraction</em> seems to apply to the definition of the DIP. If, for example, we imagine that we consider a Domain Model, the business logic, as the essence we'd like to amplify, we may rightfully consider a particular persistence mechanism a detail. Even more concretely, if you want to take restaurant reservations via a <a href="https://en.wikipedia.org/wiki/REST">REST</a> API, the <a href="/2020/01/27/the-maitre-d-kata">business rules that determine whether or not you can accept a reservation</a> shouldn't depend on a particular database technology.
103103
</p>
104104
<p>
105105
While code examples are useful, there's evidently a risk that if the examples are too much alike, it may constrain readers' thinking. All Martin's examples seem to involve IoC, but for years now, I've mostly been interested in the Dependency Inversion <em>Principle</em> itself. Abstractions should not depend on details. That's the kernel of the idea.
@@ -123,7 +123,7 @@ <h3 id="53b158bd928e4883992c578be989baf5">
123123
While you can always model <a href="/2017/07/10/pure-interactions">pure interactions</a> with free <a href="/2022/03/28/monads">monads</a>, it's usually not necessary. In most cases, an <a href="/2020/03/02/impureim-sandwich">Impureim Sandwich</a> suffices.
124124
</p>
125125
<p>
126-
The sample code base that accompanies <a href="/2021/06/14/new-book-code-that-fits-in-your-head">Code That Fits in Your Head</a> takes a similar approach. While it's <a href="">possible to refactor it to an explicit Impureim Sandwich</a>, the code presented in the book follows the kindred notion of <a href="https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell">Functional Core, Imperative Shell</a>.
126+
The sample code base that accompanies <a href="/2021/06/14/new-book-code-that-fits-in-your-head">Code That Fits in Your Head</a> takes a similar approach. While it's <a href="/2024/12/16/a-restaurant-sandwich">possible to refactor it to an explicit Impureim Sandwich</a>, the code presented in the book follows the kindred notion of <a href="https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell">Functional Core, Imperative Shell</a>.
127127
</p>
128128
<p>
129129
The code base implements an online restaurant reservation system, and the Domain Model is a set of data structures and pure functions that operate on them. The central and most complex function is the <code>WillAccept</code> method <a href="/2020/11/30/name-by-role">shown here</a>. It decides whether to accept a reservation request, based on restaurant table configurations, existing reservations, business rules related to seating durations, etc. It does this without depending on details. It doesn't know about databases, the application's configuration system, or how to send emails in case it decides to accept a reservation.

0 commit comments

Comments
 (0)