Exemplo n.º 1
0
void MainWindow::testVisitor()
{
    Visitor *pVisitorA = new ConcreteVisitorA();
    Visitor *pVisitorB = new ConcreteVisitorB();

    Element *pElementA = new ConcreteElementA();
    Element *pElementB = new ConcreteElementB();

    pElementA->Accept(pVisitorA);
    pElementB->Accept(pVisitorB);
}
Exemplo n.º 2
0
int main(int argc, const char * argv[]) {
    Visitor v;
    
    Element* elementA = new ElementA();
    Element* elementB = new ElementB();
    
    elementA->Accept(v);
    elementB->Accept(v);
    
    delete elementA;
    delete elementB;
    
    return 0;
}
Exemplo n.º 3
0
using namespace std; int main(int argc, char* argv[])
{
	Visitor* vis = new ConcreteVisitorA();
	Element* elm = new ConcreteElementA();
	elm->Accept(vis); 
	delete elm;
	delete vis;
	return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
    Visitor *vis = new ConcreteVisitorB();
    Element *elm = new ConcreteElementB();
    elm->Accept(vis);

    system("pause");
    return 0;
}
Exemplo n.º 5
0
int main()
{
    Visitor *pVisitorA = new ConcreateVisitorA();
    Element *pElement  = new ConcreateElementA();

    pElement->Accept(*pVisitorA);

    delete pElement;
    delete pVisitorA;

    return 0;
}
Exemplo n.º 6
0
void Writer::Write(const Element& elementRoot, std::ostream& ostr) { 
   Writer writer(ostr);
   elementRoot.Accept(writer);
   ostr.flush(); // all done
}
Exemplo n.º 7
0
///Visitor 模式则提供了一种解决方案:将更新(变更)封装到一个类中(访问操作),并 由待更改类提供一个接收接口,则可达到效果。
///Visitor 模式在不破坏类的前提下,为类提供增加新的新操作。Visitor 模式的关键是双分派(Double-Dispatch)的技术。C++语言支持的是单分派。
void VisitorTest() {
    Visitor* vis = new ConcreteVisitorA();
    Element* elm = new ConcreteElementA();
    elm->Accept(vis);
}
Exemplo n.º 8
0
void test_visitor()
{
	Visitor* pVis = new ConcreteVisitorA();
	Element* pElm = new ConcreteElementA();
	pElm->Accept(pVis);
}