jeudi 14 mai 2020

C++ Builder combined with Visitor

I am designing a GUI Framework based on Composite pattern (Window class inherits from UIComponent class)

I need to implement a class that will create a window consisting of some UIComponents. I think that Builder pattern is a good decision, because it is a complex structure. But I found two variants of this solution:

a plain Builder pattern

dialogWindowBuilder = new DialogWindowBuilder;
dialogWindowBuilder.AddButton(button);
window = dialogWindowBuilder.GetResult();

or a Builder with Visitor pattern

window = new Window;
dialogWindowVisitor = new DialogWindowVisitor;
dialogWindowVisitor.AddButton(button);
window.build(dialogWindowVisitor);

As I have read here https://refactoring.guru/design-patterns/visitor the Visitor pattern is a good addition for the components structure. I could not find anywhere any information about combining Build with Visitor.

What do you think about this?

Aucun commentaire:

Enregistrer un commentaire