UP | HOME

原型模式

define-struct内置copy功能:

(define-structure (book keyword-constructor copier) 
  title authors publisher year isbn)

(define bazaar 
  (make-book 
   'title "The Cathedral and the Bazaar"
   'authors "Eric S. Raymond"
   'publisher "O'Reilly"
   'year 1999
   'isbn 0596001088))

;; "[the name of structure]?": checks if an object is an instance of the structure 
(book? bazaar) ;; #f
;; "copy-[structure name]" : copy a structure
(define cathedral (copy-book bazaar)) ;; cathedral

Previous:单例模式

Home:目录