Model extensible behavior with Common Lisp CLOS
8 steps · about 3 h 30 min · Intermediate
- Define classes and slots (reference, Common Lisp HyperSpec, 30 min)
Create the domain vocabulary with explicit initialization, access and inheritance choices.
- Construct validated instances (reference, Common Lisp HyperSpec, 20 min)
Exercise initialization rules through the standard instance-construction protocol.
- Declare a generic operation (reference, Common Lisp HyperSpec, 25 min)
Name behavior independently from any one representation or receiver class.
- 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.
- 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.
- Define meaningful conditions (reference, Common Lisp HyperSpec, 25 min)
Represent recoverable domain failures as typed conditions carrying useful context.
- Handle conditions outside core logic (reference, Common Lisp HyperSpec, 25 min)
Separate policy about reporting or recovery from the operation that detects the problem.
- Offer explicit restarts (reference, Common Lisp HyperSpec, 25 min)
Finish with named recovery options that callers can invoke without unwinding all useful state.