next up previous
Next: 13 シミュレーション例 Up: 12 オブジェクト指向プログラミング Previous: 12.4 スーパクラス

12.5 多重継承

直接の親になるクラスを複数指定できる機能を多重継承機能 と呼びます.CLOSのクラスシステムは多重継承機能を持ちます.

(defclass a () (a1 a2 a3))
(defclass b (a) (b1 b2))
(defclass c () (c1))
(defclass d (c) (d1 d2))
(defclass e (b d) (e1 e2))

> (setq x (make-instance 'e))
#<E @ #x205167e2>

> (describe x)
#<E @ #x205167e2> is an instance of #<STANDARD-CLASS E>:
 The following slots have :INSTANCE allocation:
  C1   <unbound>
  D1   <unbound>
  D2   <unbound>
  A1   <unbound>
  A2   <unbound>
  A3   <unbound>
  B1   <unbound>
  B2   <unbound>
  E1   <unbound>
  E2   <unbound>
多重継承の場合の,探索の優先順位は,(1)ネットワークの末端からスタート. (2) スーパクラスで左側から辿っていないものを優先してたどる.(3)今辿ろ うとしているスーパクラスが,別の道からも辿ることがでる場合には,それを 辿らずに(2)の処理を行う.(4)辿るクラスがtクラスになったらば終了する. というものになります.

generated through LaTeX2HTML. M.Inaba 平成18年5月6日