Skip to Content.
Sympa Menu

patterns-discussion - [patterns-discussion] Pattern-Oriented Programming

patterns-discussion AT lists.siebelschool.illinois.edu

Subject: General talk about software patterns

List archive

[patterns-discussion] Pattern-Oriented Programming


Chronological Thread 
  • From: "Mike Beedle" <beedlem AT e-architects.com>
  • To: <patterns-discussion AT cs.uiuc.edu>
  • Subject: [patterns-discussion] Pattern-Oriented Programming
  • Date: Fri, 22 Oct 2004 12:39:35 -0500
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/patterns-discussion>
  • List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>

;;-----------------------------------------

;; PATTERN LIBRARY – first example

;;-----------------------------------------

;; This is a Pattern Library (short)

;; i.e. Macros defining Patterns

;; like Strategy, etc.

;;---------------------------------

(defmacro make-strategy-structure(baseclass derivedclass method generic function initvalue)

  `(progn

    (defclass ,baseclass ()

     ((,method :initform 0.0

                                     :initarg :start

                                     :accessor ,method)))

     (defclass ,derivedclass (,baseclass)

                                                ((,method :initform ,initvalue

                                                                                     :initarg :start

                                                                                     :accessor ,method)))

   (defgeneric ,generic (,baseclass))

   (defmethod ,generic ((base-class-instance ,baseclass))

                         (format t "~%We are in the generic")

                         (funcall ,function)

       (print (,method base-class-instance))

                         )))

 

(defmacro make-strategy(baseclass derivedclass method initvalue)

  `(progn

             (defclass ,derivedclass (,baseclass)

                                                ((,method :initform ,initvalue

                                                                                     :initarg :start

                                                                                     :accessor ,method)))

                         ))

 

;;----------------------------------

;; Standard Existing Code to Reuse

;;----------------------------------

(defun defunexecute ()

   (format t "~%We are in the defun")

   )

 

;;--------------------------------------

;; PROGRAM by instantiating patterns

;;--------------------------------------

;; Program using the Pattern Library

;; creates interacting inter-connected

;; "patterns"

;;--------------------------------------

(defparameter s1 nil)

(defparameter s2 nil)

(format t "~%~%Create a Strategy Hierarcy and execute it:~%")

(make-strategy-structure service logging-service parameter executeGen #'defunexecute 'testfile)

(setf s1 (make-instance 'logging-service :start 'myfile))

(print (parameter s1))

;; executing generic

(print (executeGen s1))

 

(format t "~%~%Create another Strategy and execute it:~%")

(make-strategy service db-logging-service parameter 'testdb)

(setf s2 (make-instance 'db-logging-service :start 'mydb))

;; executing method

(print (parameter s2))

 

;; print pattern code

;(pprint (macroexpand-1 '(make-strategy-structure service logging-service parameter execute #'defunexecute 'testfile)))

 




Archive powered by MHonArc 2.6.16.

Top of Page