00001 // From: 00002 // http://en.wikipedia.org/wiki/Visitor_pattern 00003 00004 #include "CarElementVisitor.h" 00005 #include "CarElement.h" 00006 #include "Wheel.h" 00007 #include "Engine.h" 00008 #include "Body.h" 00009 #include "Car.h" 00010 #include "CarElementPrintVisitor.h" 00011 #include "CarElementDoVisitor.h" 00012 00013 int main() 00014 { 00015 Car car; 00016 CarElementPrintVisitor printVisitor; 00017 CarElementDoVisitor doVisitor; 00018 00019 printVisitor.visitCar(car); 00020 doVisitor.visitCar(car); 00021 00022 return 0; 00023 } 00024 00025 /*Output: 00026 00027 Visiting car 00028 Visiting front left wheel 00029 Visiting front right wheel 00030 Visiting back left wheel 00031 Visiting back right wheel 00032 Visiting body 00033 Visiting engine 00034 Visited car 00035 00036 Starting my car 00037 Kicking my front left wheel 00038 Kicking my front right wheel 00039 Kicking my back left wheel 00040 Kicking my back right wheel 00041 Moving my body 00042 Starting my engine 00043 Stopped car 00044 */