<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></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></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></div><div>-Hans</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am So., 7. Feb. 2021 um 08:59 Uhr schrieb Marco Antoniotti <<a href="mailto:marco.antoniotti@unimib.it">marco.antoniotti@unimib.it</a>>:<br></div><blockquote class="gmail_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></div><div><span style="font-family:monospace">procedure foo is<br></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></span></div><div><span style="font-family:monospace">end</span></div><div><br></div><div><br></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><br></div><div>Have I boiled down to the essentials?  How do you do the rolling eyes emoticon?</div><div><br></div><div>All the best</div><div><br></div><div>Marco</div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 6, 2021 at 10:50 PM Pascal Bourguignon <<a href="mailto:pjb@informatimago.com" target="_blank">pjb@informatimago.com</a>> wrote:<br></div><blockquote class="gmail_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>
> You have a class. This class uses some other class.<br>
> But by using or creating an instance of this other class directly you create a dependency on something concrete.<br>
> 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>
> ‚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>
> A similar thing could certainly be done by just using a constructor parameter (strategy pattern).<br>
> But I think the important part here is the dependency on just an interface and not on a concrete implementation. For flexibility.<br>
<br>
<br>
With some code:<br>
<br>
;;;------------------------------------------------------------<br>
<br>
(defclass used ()<br>
   ())<br>
<br>
(defmethod used-stuff ((self used))<br>
   'stuff)<br>
<br>
;;; ---<br>
<br>
(defclass user ()<br>
   ((used :reader used)))<br>
<br>
(defmethod initialize-instance :after ((self user) &key &allow-other-keys)<br>
   (setf (slot-value self 'used) (make-instance 'used #|OOPS, <br>
Dependency!|#)))<br>
<br>
(defmethod user-stuff ((self user))<br>
   ;; Not a real dependency on the used class,<br>
   ;; it's a dependency on the used-stuff generic function (interface).<br>
   (used-stuff (used self)))<br>
<br>
;;; ---<br>
<br>
(defclass client ()<br>
   ())<br>
<br>
(defmethod create-user ((self client))<br>
   ;; The class client depends directly on the user class,<br>
   ;; and indirectly on the used class.<br>
   (make-instance 'user))<br>
<br>
<br>
;;;------------------------------------------------------------<br>
<br>
(defclass used ()<br>
   ())<br>
<br>
(defmethod used-stuff ((self used))<br>
   'stuff)<br>
<br>
;;; ---<br>
<br>
(defclass user ()<br>
   ((used :initarg :used :reader used)))<br>
<br>
;; The user class has no more any dependency on the used class.<br>
<br>
(defmethod user-stuff ((self user))<br>
   ;; Not a real dependency on the used class,<br>
   ;; it's a dependency on the used-stuff generic function (interface).<br>
   (used-stuff (used self)))<br>
<br>
;;; ---<br>
<br>
(defclass client ()<br>
   ())<br>
<br>
(defmethod create-user ((self client))<br>
   ;; The class client depends explicitely on the user and used classes.<br>
   ;; But now, the class user doesn't depend directly on the used class;<br>
   ;; this dependency is injected by the client into the user classe:<br>
   (make-instance 'user :used (make-instance 'used)))<br>
<br>
<br>
;;;------------------------------------------------------------<br>
<br>
;; Notably if the client wants the user to use another used class:<br>
<br>
(defclass variant-used (used)<br>
   ())<br>
(defmethod used-stuff ((self variant-used))<br>
   'variant-stuff)<br>
<br>
(defmethod create-user ((self client))<br>
   ;; only the client needs to be changed; the user class won't know<br>
   ;; the difference:<br>
   (make-instance 'user :used (make-instance 'variant-used)))<br>
<br>
<br>
-- <br>
__Pascal Bourguignon__<br>
<br>
</blockquote></div><br clear="all"><br>-- <br><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-align:start;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-align:start;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-align:start;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-align:start;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-align:start;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-align:start;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 style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;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-align:start;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-align:start;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-align:start;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-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration:none"></span><a href="http://bimib.disco.unimib.it/" style="font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">http://bimib.disco.unimib.it</a><br style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;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-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;display:inline;float:none">Viale Sarca 336</span><br style="color:rgb(0,0,0);font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;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-align:start;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></div></div></div></div>
</blockquote></div>