Source

qtility / metaclass.lisp

;;;; metaclass.lisp
;;;; Copyright (c) 2012 Robert Smith

(in-package #:qtl)

;;; Abstract Classes
;;; A metaclass which cannot be instantiated.

(defclass abstract-class (standard-class) ())

(defmethod make-instance ((class abstract-class) &rest ignored)
  (declare (ignore ignored))
  (error "Attempting to instantiate an abstract class ~A"
	 (class-name class)))

(defmethod validate-superclass ((class abstract-class)
                                (superclass standard-class))
  t)

(defmethod validate-superclass ((class standard-class)
				(superclass abstract-class))
  t)


;;; Final Classes
;;; A metaclass which cannot be subclassed.

(defclass final-class (standard-class) ())

(defmethod validate-superclass ((class final-class) 
				(superclass standard-class))
  t)

(defmethod validate-superclass ((class standard-class)
				(superclass final-class))
  (error "Attempting to subclass the final class ~A" superclass))