Overriding methods of a protocol can be implemented with the
reify form, while overrides for interfaces and classes can be implemented with the
proxy form. These two forms are meant to provide a way to make anonymous instances of protocols and interfaces, but these forms double as a simple way to write method overrides.
We'll use the
PCan protocol from the last section in the following examples. The following is the
PCan protocol, in case you don't have it from the last section:
user> (defprotocol PCan (can-size [_]) (open-can [_]) (label [_])) PCan
In the following example,
reify is used to make a locally-scoped instance of the
PCan class. Because the returned class can be requested by its ...