Pattern, Abstract Factory / Factory

Manfred Bergmann manfred.bergmann at me.com
Sun Feb 7 10:28:28 UTC 2021



> Am 07.02.2021 um 09:45 schrieb Hans Hübner <hans.huebner at gmail.com>:
> 
> Am So., 7. Feb. 2021 um 09:35 Uhr schrieb Manfred Bergmann <manfred.bergmann at me.com>:
> > Am 07.02.2021 um 09:23 schrieb Hans Hübner <hans.huebner at gmail.com>:
> > 
> > Am So., 7. Feb. 2021 um 09:20 Uhr schrieb Manfred Bergmann <manfred.bergmann at me.com>:
> > But fundamentally, you also can’t create an instance of a class in Common Lisp from just the symbol. The class definition must be known.
> > 
> > This simply is untrue.  You can use FIND-CLASS to find a class named by a symbol and then instantiate it.
> 
> Well, OK. Sure. But when I do that I have again a dependency on the concrete class, or? And it would be similar as knowing the class right from the start.
> 
> You don't.  You have a dependency on the name of a class.  The name could refer to two entirely different classes between invocations of FIND-CLASS.  The name could also come from an external source.  Thus, this is purely a run-time dependency and it would be quite possible that FIND-CLASS returns NIL if given a symbol that does not designate a currently-defined class. 


OK, nice.
This is probably why make-instance `foo can work instead of this boilerplate Abstract Factory in Java.
Actually looks like FIND-CLASS is the simple version of dependency-injection.


Manfred


More information about the pro mailing list