Model extensible behavior with Common Lisp CLOS

8 steps · about 3 h 30 min · Intermediate

  1. Define classes and slots (reference, Common Lisp HyperSpec, 30 min)

    Create the domain vocabulary with explicit initialization, access and inheritance choices.

  2. Construct validated instances (reference, Common Lisp HyperSpec, 20 min)

    Exercise initialization rules through the standard instance-construction protocol.

  3. Declare a generic operation (reference, Common Lisp HyperSpec, 25 min)

    Name behavior independently from any one representation or receiver class.

  4. Specialize methods on arguments (reference, Common Lisp HyperSpec, 30 min)

    Implement behavior chosen from the types of one or several arguments rather than manual conditionals.

  5. Combine primary and auxiliary methods (reference, Common Lisp HyperSpec, 30 min)

    Use before, after and around methods only where their ordering makes the extension clearer.

  6. Define meaningful conditions (reference, Common Lisp HyperSpec, 25 min)

    Represent recoverable domain failures as typed conditions carrying useful context.

  7. Handle conditions outside core logic (reference, Common Lisp HyperSpec, 25 min)

    Separate policy about reporting or recovery from the operation that detects the problem.

  8. Offer explicit restarts (reference, Common Lisp HyperSpec, 25 min)

    Finish with named recovery options that callers can invoke without unwinding all useful state.