blob: 5819438ad4ea5a89fb4367fee04938f427c18082 (
plain) (
tree)
|
|
;;; Port of https://stackoverflow.com/questions/3984296/model-view-controller-design-pattern-code-example.
;;; Model and Controller classes.
;;;
;;; Probably better to just use ltk.
(require "json")
(defpackage #:mc
(:use #:openlisp #:json)
(:export
#:mc-server)
)
(in-package #:mc)
(defclass <graph-gui-stub> () ((button :accessor button)
(model :accessor model)
(controller :writer controller)))
(defmethod initialize-object :after ((self <graph-gui-stub>) initargs)
(setf (button self) (create (class <button>) 'm "Click Me"))
(setf (model self) (create (class <graph-data>)))
(setf (controller self) (create (class <graph-controller>) 'm (model self) 'b (button self))))
(defclass <graph-data> () ((number :reader number :writer get-number)))
(defmethod initialize-object :after ((self <graph-data>) initargs)
(setf (number self) 10))
(defgeneric increase-number (data))
(defmethod increase-number ((data <graph-data>))
(setf (number data) (+ (get-number data) 10)))
(defclass <graph-controller> () ((model :initarg m :reader model)
(button :initarg b :reader button)))
(defmethod initialize-object :after ((self <graph-controller>) initargs)
(set-click-handler (button self) self #'on-button-clicked))
(defgeneric on-button-clicked (controller))
(defmethod on-button-clicked ((controller <graph-controller>))
(increase-number (model controller)))
(provide "mc")
|