Image for Visitor pattern

Visitor pattern

The Visitor pattern is a design approach in software that separates operations from the objects they work on. Imagine a collection of different items (like files, images, or shapes). Instead of each item handling every possible operation, a separate "visitor" performs actions—like printing, analyzing, or exporting—on these items. This way, new operations can be added without changing the original item classes, promoting flexibility and cleaner code. Essentially, it allows you to "visit" objects and perform specific tasks differently, depending on the visitor, while keeping object structures stable.