/**
* Copyright (C) 2022 by Martin Robillard. See https://codesample.info/about.html
*/
package e2.chapter8;
public class implements CardSourceVisitor
{
@Override
public void visitCompositeCardSource(CompositeCardSource pCompositeCardSource) {
for( CardSource source : pCompositeCardSource ) {
source.accept(this);
}
}
@Override
public void visitDeck(Deck pDeck)
{}
@Override
public void visitCardSequence(CardSequence pCardSequence)
{}
}
Providing an abstract class that implements the Visitor
interface
offers two main benefits:
visit
methods, concrete visitors
that inherit from the abstract class only need to override the methods
relevant to a specific operation. In realistic applications, the element
type hierarchy may have dozens of types, with as many visit
methods.accept
methods, the
abstract class can provide a default traversal strategy, further reducing
code duplication between different concrete visitors.Providing an abstract class that implements the Visitor
interface
offers two main benefits:
visit
methods, concrete visitors
that inherit from the abstract class only need to override the methods
relevant to a specific operation. In realistic applications, the element
type hierarchy may have dozens of types, with as many visit
methods.accept
methods, the
abstract class can provide a default traversal strategy, further reducing
code duplication between different concrete visitors.