Hello.
I am trying to discover design patterns and how they are implemented in Common Lisp.
According to Peter Norvig (http://norvig.com/design-patterns/design-patterns.pdf) and this source (https://wiki.c2.com/?AreDesignPatternsMissingLanguageFeatures) some design pattern are more simple in Common Lisp, or are actually not needed at all because the language can be extended to achieve the same thing: extendability, separation, abstraction.
Taking an Abstract Factory for example, the sources say that metaclasses can help do this. I’ve read a bit about metaclasses and the MOP but I fail to see how. I could probably come up with something.
A GUI framework for example. I could create something like this :
— (defclass meta-button (standard-class) ((gui-button-backend :initform nil :accessor gui-button-backend)))
(defmethod closer-mop:validate-superclass ((class meta-button) (superclass standard-class)) t)
(defclass button () () (:metaclass meta-button)) (defun make-button () (make-instance 'button)) —
And configure a QT or GTK, Motif (or whatever) button backend to the metaclass on startup (or so). But I think this would just be the pattern somehow turned into a metaclass. Doesn’t feel like the right thing.
Does anyone know what Peter Norvig had in mind when he said that metaclasses can be used instead of Abstract Factory pattern?
Cheers, Manfred