My 2c: It seems to me that too many things are getting mixed in (static/dynamic, abstract/concrete, etc). Dependency injection is only about dependencies and dependency inversion is also about abstraction. <div id="yMail_cursorElementTracker_1612779758267">I would interpret dependency inversion as turning a private language of two parts into a public language that all parts depend on.</div><div id="yMail_cursorElementTracker_1612779959293">For dependency injection, something like: A depends on B. Let's introduce a combinator C that depends on both (modified) A and B, which constructs a new object from mutually independent A and B. We can then use dependency inversion to make all of them use a public language, so that C can be reused for different As and Bs.</div><div id="yMail_cursorElementTracker_1612779947536"> <br> <blockquote style="margin: 0 0 20px 0;"> <div style="font-family:Roboto, sans-serif; color:#6D00F6;"> <div>On Sun, Feb 7, 2021 at 9:27, Hans Hübner</div><div><hans.huebner@gmail.com> wrote:</div> </div> <div style="padding: 10px 0 0 20px; margin: 10px 0 0 0; border-left: 1px solid #6D00F6;"> <div id="yiv0126157129"><div><div dir="ltr">DI Frameworks live on a different plane than most of the micro-patterns in the GoF class: They try to solve the problem that when using a framework, composing the components that a specific framework application needs can be difficult and complex. This is done by annotating the application component that makes use of a framework feature (using configuration files or, more recently, source code annotations), and then having the framework runtime collect the dependencies from the annotations to build the right set of components. Effectively, instead of statically linking the application to the framework, the linking is performed at run-time and, as the linking information is richer than in traditional linking systems (i.e. an application-level annotation instead of just a function name), it can do a lot of things that are typically aspects of systems written in dynamically typed programming languages.<div><br clear="none"></div><div>The applicability of dependency injection really depends on the complexity of the framework that is being talked about. In simple, and in particular in framework-less systems, one does not really need a framework-specific, configurable, run-time linking component. Most Lisp systems do not actually depend on a framework, and Lisp - as a dynamic language - provides for plenty of run-time features that can be used to achieve what is the magic sauce in dependency injection frameworks. One may want to standardize how component linkage is performed in a large Lisp system, of course, but the challenges would be different as much of the tooling to perform the actual work is available right away.</div><div><br clear="none"></div><div>The same can be said about many of the patterns that are used in the OO and Java world, of course. They often provide solution architectures to problems that are hard to solve given the constraints of - in particular - Java, and for which trivially easy solutions can be devised in Lisp on the fly without having to resort to a named pattern.</div><div><br clear="none"></div><div>-Hans</div></div><br clear="none"><div class="yiv0126157129gmail_quote"><div class="yiv0126157129gmail_attr" dir="ltr">Am So., 7. Feb. 2021 um 08:59 Uhr schrieb Marco Antoniotti <<a rel="nofollow noopener noreferrer" shape="rect" ymailto="mailto:marco.antoniotti@unimib.it" target="_blank" href="mailto:marco.antoniotti@unimib.it">marco.antoniotti@unimib.it</a>>:<br clear="none"></div><div class="yiv0126157129yqt4093393447" id="yiv0126157129yqt96985"><blockquote class="yiv0126157129gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><div dir="ltr"><div>OK.</div><div><br clear="none"></div><div><span style="font-family:monospace;">procedure foo is<br clear="none"></span></div><div><span style="font-family:monospace;"> x : Integer := 42;</span></div><div><span style="font-family:monospace;">begin</span></div><div><span style="font-family:monospace;"> ...<br clear="none"></span></div><div><span style="font-family:monospace;">end</span></div><div><br clear="none"></div><div><br clear="none"></div><div><div>Now <span style="font-family:monospace;">foo</span> depends on the hardwired '42' (as is should, one may argue :) ). And we are not even talking about "classes" or Lisp here.<br clear="none"><br clear="none"></div><div>Have I boiled down to the essentials? How do you do the rolling eyes emoticon?</div><div><br clear="none"></div><div>All the best</div><div><br clear="none"></div><div>Marco</div><div><br clear="none"></div></div></div><br clear="none"><div class="yiv0126157129gmail_quote"><div class="yiv0126157129gmail_attr" dir="ltr">On Sat, Feb 6, 2021 at 10:50 PM Pascal Bourguignon <<a rel="nofollow noopener noreferrer" shape="rect" ymailto="mailto:pjb@informatimago.com" target="_blank" href="mailto:pjb@informatimago.com">pjb@informatimago.com</a>> wrote:<br clear="none"></div><blockquote class="yiv0126157129gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">Le 06/02/2021 à 22:37, Manfred Bergmann a écrit :<br clear="none">
> You have a class. This class uses some other class.<br clear="none">
> But by using or creating an instance of this other class directly you create a dependency on something concrete.<br clear="none">
> That’s not what you want, because you might want to replace this with something else if required. For example with a mock or fake implementation in a test.<br clear="none">
> ‚Dependency injection‘ allows you to declare this dependency with just an interface/protocol and have some other facility (the dependency injection framework) ‚inject‘ a concrete object at run-time.<br clear="none">
> A similar thing could certainly be done by just using a constructor parameter (strategy pattern).<br clear="none">
> But I think the important part here is the dependency on just an interface and not on a concrete implementation. For flexibility.<br clear="none">
<br clear="none">
<br clear="none">
With some code:<br clear="none">
<br clear="none">
;;;------------------------------------------------------------<br clear="none">
<br clear="none">
(defclass used ()<br clear="none">
())<br clear="none">
<br clear="none">
(defmethod used-stuff ((self used))<br clear="none">
'stuff)<br clear="none">
<br clear="none">
;;; ---<br clear="none">
<br clear="none">
(defclass user ()<br clear="none">
((used :reader used)))<br clear="none">
<br clear="none">
(defmethod initialize-instance :after ((self user) &key &allow-other-keys)<br clear="none">
(setf (slot-value self 'used) (make-instance 'used #|OOPS, <br clear="none">
Dependency!|#)))<br clear="none">
<br clear="none">
(defmethod user-stuff ((self user))<br clear="none">
;; Not a real dependency on the used class,<br clear="none">
;; it's a dependency on the used-stuff generic function (interface).<br clear="none">
(used-stuff (used self)))<br clear="none">
<br clear="none">
;;; ---<br clear="none">
<br clear="none">
(defclass client ()<br clear="none">
())<br clear="none">
<br clear="none">
(defmethod create-user ((self client))<br clear="none">
;; The class client depends directly on the user class,<br clear="none">
;; and indirectly on the used class.<br clear="none">
(make-instance 'user))<br clear="none">
<br clear="none">
<br clear="none">
;;;------------------------------------------------------------<br clear="none">
<br clear="none">
(defclass used ()<br clear="none">
())<br clear="none">
<br clear="none">
(defmethod used-stuff ((self used))<br clear="none">
'stuff)<br clear="none">
<br clear="none">
;;; ---<br clear="none">
<br clear="none">
(defclass user ()<br clear="none">
((used :initarg :used :reader used)))<br clear="none">
<br clear="none">
;; The user class has no more any dependency on the used class.<br clear="none">
<br clear="none">
(defmethod user-stuff ((self user))<br clear="none">
;; Not a real dependency on the used class,<br clear="none">
;; it's a dependency on the used-stuff generic function (interface).<br clear="none">
(used-stuff (used self)))<br clear="none">
<br clear="none">
;;; ---<br clear="none">
<br clear="none">
(defclass client ()<br clear="none">
())<br clear="none">
<br clear="none">
(defmethod create-user ((self client))<br clear="none">
;; The class client depends explicitely on the user and used classes.<br clear="none">
;; But now, the class user doesn't depend directly on the used class;<br clear="none">
;; this dependency is injected by the client into the user classe:<br clear="none">
(make-instance 'user :used (make-instance 'used)))<br clear="none">
<br clear="none">
<br clear="none">
;;;------------------------------------------------------------<br clear="none">
<br clear="none">
;; Notably if the client wants the user to use another used class:<br clear="none">
<br clear="none">
(defclass variant-used (used)<br clear="none">
())<br clear="none">
(defmethod used-stuff ((self variant-used))<br clear="none">
'variant-stuff)<br clear="none">
<br clear="none">
(defmethod create-user ((self client))<br clear="none">
;; only the client needs to be changed; the user class won't know<br clear="none">
;; the difference:<br clear="none">
(make-instance 'user :used (make-instance 'variant-used)))<br clear="none">
<br clear="none">
<br clear="none">
-- <br clear="none">
__Pascal Bourguignon__<br clear="none">
<br clear="none">
</blockquote></div><br clear="all"><br clear="none">-- <br clear="none"><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;display:inline;float:none;">Marco Antoniotti, Associate Professor</span><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration:none;"> </span><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration:none;"> </span><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;display:inline;float:none;">tel.</span><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;text-decoration:none;display:inline;float:none;white-space:pre-wrap;"> </span><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;display:inline;float:none;">+39 - 02 64 48 79 01</span><br clear="none" style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;"><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;display:inline;float:none;">DISCo, Università Milano Bicocca U14 2043</span><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration:none;"> </span><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration:none;"> </span><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration:none;"></span><a rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="http://bimib.disco.unimib.it/" style="font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">http://bimib.disco.unimib.it</a><br clear="none" style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;"><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;display:inline;float:none;">Viale Sarca 336</span><br clear="none" style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;"><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;display:inline;float:none;">I-20126 Milan (MI) ITALY</span><br clear="none"></div></div></div></div>
</blockquote></div></div>
</div></div> </div> </blockquote></div>