From harness-claude
Implements JavaScript Visitor pattern to add operations to complex object structures like ASTs, file trees, or DOM without modifying element classes. Use for many unrelated operations on stable hierarchies.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Add new operations to object structures without modifying the objects
Implements GOF Visitor pattern in TypeScript to add operations like evaluation, printing, counting to object structures such as ASTs without modifying classes. Use for tree traversals and double dispatch.
Generates Visitor pattern for PHP 8.4 to perform operations on object structures without modifying element classes. Includes visitor interface, concrete visitors, visitable elements, and unit tests.
Author OpenRewrite recipes in TypeScript for automated code transformations. Covers structure, visitor patterns, matching, templates, testing strategies, and troubleshooting.
Share bugs, ideas, or general feedback.
Add new operations to object structures without modifying the objects
accept(visitor) method on each element class in the object structure.accept calls the visitor's corresponding method, passing this (double dispatch).visitFile, visitFolder).class File {
constructor(name, size) {
this.name = name;
this.size = size;
}
accept(visitor) {
return visitor.visitFile(this);
}
}
class Folder {
constructor(name, children) {
this.name = name;
this.children = children;
}
accept(visitor) {
return visitor.visitFolder(this);
}
}
const sizeCalculator = {
visitFile(file) {
return file.size;
},
visitFolder(folder) {
return folder.children.reduce((sum, child) => sum + child.accept(this), 0);
},
};
The Visitor pattern achieves the open/closed principle by separating operations from the object structure. New operations (visitors) can be added without modifying existing element classes. This is heavily used in compilers and AST processors (e.g., Babel plugins are visitors).
Trade-offs:
When NOT to use:
map/reduce over an array is clearerhttps://patterns.dev/javascript/visitor-pattern