Design pattern solutions as language features

When programming in a very-high-level language like Lisp, the user is relieved from inventing solutions to design patterns, as the solutions are built-into the language itself.  I present two examples here.  

 
The first is for the Visitor pattern, which provide an  opportunity to add new operations to a data structure, without modifying it.  In  other words, adding new methods to a class without sub-classing.  We present the solution in Java and Common Lisp.  The example specifies a Component base class from which different components like HDD, RAM etc are derived.  There are three versions of Java code.  Each present an improvement over the previous.  The third version provides an interface that supports a visitor, so that the user of the Component class can add new features, without touching the class hierarchy.  The problem is that, the classes has to be re-defined once so that it can support a visitor.  Next we present the same library in Common Lisp, where the designer need not even worry about coding a solution to the visitor pattern, as the language already provides a solution in the form of generic functions. 
 
The next example shows how first-class functions can act as the natural solution for Strategy and many other patterns.
 

Click here to download:
Components_ver1.java (2 KB)

Click here to download:
Components_ver2.java (4 KB)

Click here to download:
Components_ver3.java (4 KB)

Click here to download:
components.lisp (2 KB)

Click here to download:
strategy.ss (0 Bytes)