samedi 29 août 2020

Operation in composite design pattern vs add a new visitor in visitor design pattern

Eric Gamma's Design Patterns book explains that a composite structure may declare operations:

https://i.stack.imgur.com/OGqbO.png

Such operations are propagated recursively by non-leaf operators.

On the other hand, we may get the same result by using a visitor design pattern to create visitors that visit the composite structure and do the operation.

So, is there any reason why one would chose to add an operation in the composite rather than creating a new visitor for each desired operation? Or vice versa?

Aucun commentaire:

Enregistrer un commentaire