22:
169:
should be used when the visitor must remain in memory. This occurs when the visitor is configured with a number of parameters that must be kept in memory for a later use of the visitor (for example, for storing the rendering options of a 3D scene renderer).
177:. In doing so, it is ensured that the single-serving visitor can be called later with its parameters unchanged (in this particular case "single-serving visitor" is an abuse of language since the visitor can be used several times).
154:
The single-serving visitor pattern should be used when visitors do not need to remain in memory. This is often the case when visiting a hierarchy of objects (such as when the
173:
However, if there should be only one instance of such a visitor in a whole program, it can be a good idea to implement it both as a single-serving visitor and as a
46:
of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to be
420:
method, a single-serving visitor is created then discarded, which is time-consuming. In contrast, the singleton only performs one allocation.
98:
70:
77:
84:
66:
1280:
139:
117:
393:. With a single-serving visitor, it is ensured that visitors are allocated when needed and destroyed once useless.
674:
If the single-serving visitor has to be initialised, the parameters have to be passed through the static method:
43:
91:
39:
55:
162:) to perform a single task on it, for example counting the number of cameras in a 3D scene.
131:
32:
146:
that is allocated, used only once, and then deleted (which is the case of most visitors).
8:
51:
1265:
1259:
174:
159:
47:
1253:
185:
The single-serving visitor is called through the intermediate of static methods.
166:
155:
143:
1274:
1262:: single-serving visitor is often applied to hierarchies of elements
38:
Please help to demonstrate the notability of the topic by citing
783:
that there is at most one instance of the single-serving visitor
399:. The visitor is created, used and free by the sole call of the
429:
864:// Note: get_instance method does not need to be public
142:. Its intent is to optimise the implementation of a
1272:
774:
424:
430:Basic implementation (without parameters)
118:Learn how and when to remove this message
1273:
903:// static methods to access parameters
786:that the visitor can be accessed later
669:
15:
1247:
13:
1038:SingleServingVisitor::get_instance
14:
1292:
1256:, from which this pattern derives
180:
1203:SingleServingVisitor::set_param2
1158:SingleServingVisitor::set_param1
397:A simpler interface than visitor
149:
67:"Single-serving visitor pattern"
20:
379:
1113:SingleServingVisitor::apply_to
682:SingleServingVisitor::apply_to
290:Implementation as a singleton:
136:single-serving visitor pattern
1:
779:This implementation ensures:
775:Implementation as a singleton
33:general notability guideline
7:
10:
1297:
158:is used together with the
40:reliable secondary sources
29:The topic of this article
31:may not meet Knowledge's
1281:Software design patterns
789:
676:
433:
291:
227:
190:
425:Implementation (in C++)
407:
384:
478:// Same as with the ].
416:. At each call of the
1086:SingleServingVisitor
1032:SingleServingVisitor
1014:SingleServingVisitor
1008:SingleServingVisitor
876:SingleServingVisitor
852:SingleServingVisitor
843:SingleServingVisitor
813:SingleServingVisitor
798:SingleServingVisitor
724:SingleServingVisitor
637:SingleServingVisitor
610:SingleServingVisitor
514:SingleServingVisitor
499:SingleServingVisitor
487:SingleServingVisitor
469:SingleServingVisitor
357:SingleServingVisitor
339:SingleServingVisitor
321:SingleServingVisitor
257:SingleServingVisitor
205:SingleServingVisitor
132:computer programming
414:Repeated allocation
391:No "zombie" objects
189:Without parameters:
670:Passing parameters
35:
1266:Singleton pattern
1260:Composite pattern
1005:// Implementation
604:// Implementation
160:composite pattern
128:
127:
120:
102:
30:
1288:
1248:Related patterns
1243:
1240:
1237:
1234:
1231:
1228:
1225:
1222:
1219:
1216:
1213:
1210:
1207:
1204:
1201:
1198:
1195:
1192:
1189:
1186:
1183:
1180:
1177:
1174:
1171:
1168:
1165:
1162:
1159:
1156:
1153:
1150:
1147:
1144:
1141:
1138:
1135:
1132:
1129:
1126:
1123:
1120:
1117:
1114:
1111:
1108:
1105:
1102:
1099:
1096:
1093:
1090:
1087:
1084:
1081:
1078:
1075:
1072:
1069:
1066:
1063:
1060:
1057:
1054:
1051:
1048:
1045:
1042:
1039:
1036:
1033:
1030:
1027:
1024:
1021:
1018:
1015:
1012:
1009:
1006:
1003:
1000:
997:
994:
991:
988:
985:
982:
979:
976:
973:
970:
967:
964:
961:
958:
955:
952:
949:
946:
943:
940:
937:
934:
931:
928:
925:
922:
919:
916:
913:
910:
907:
904:
901:
898:
895:
892:
889:
886:
883:
880:
877:
874:
871:
868:
865:
862:
859:
856:
853:
850:
847:
844:
841:
838:
835:
832:
829:
826:
823:
820:
817:
814:
811:
808:
805:
802:
799:
796:
793:
770:
767:
764:
761:
758:
755:
752:
749:
746:
743:
740:
737:
734:
731:
728:
725:
722:
719:
716:
713:
710:
707:
704:
701:
698:
695:
692:
689:
686:
683:
680:
665:
662:
659:
656:
653:
650:
647:
644:
641:
638:
635:
632:
629:
626:
623:
620:
617:
614:
611:
608:
605:
602:
599:
596:
593:
590:
587:
584:
581:
578:
575:
572:
569:
566:
563:
560:
557:
554:
551:
548:
545:
542:
539:
536:
533:
530:
527:
524:
521:
518:
515:
512:
509:
506:
503:
500:
497:
494:
491:
488:
485:
482:
479:
476:
473:
470:
467:
464:
461:
458:
455:
452:
449:
446:
443:
440:
437:
373:
370:
367:
364:
361:
358:
355:
352:
349:
346:
343:
340:
337:
334:
331:
328:
325:
322:
319:
316:
313:
310:
307:
304:
301:
298:
295:
285:
282:
279:
276:
273:
270:
267:
264:
261:
258:
255:
252:
249:
246:
243:
240:
237:
234:
231:
226:With parameters:
221:
218:
215:
212:
209:
206:
203:
200:
197:
194:
123:
116:
112:
109:
103:
101:
60:
24:
23:
16:
1296:
1295:
1291:
1290:
1289:
1287:
1286:
1285:
1271:
1270:
1254:Visitor pattern
1250:
1245:
1244:
1241:
1238:
1235:
1232:
1229:
1226:
1223:
1220:
1217:
1214:
1211:
1208:
1205:
1202:
1199:
1196:
1193:
1190:
1187:
1184:
1181:
1178:
1175:
1172:
1169:
1166:
1163:
1160:
1157:
1154:
1151:
1148:
1145:
1142:
1139:
1136:
1133:
1130:
1127:
1124:
1121:
1118:
1115:
1112:
1109:
1106:
1103:
1100:
1097:
1094:
1091:
1088:
1085:
1082:
1079:
1076:
1073:
1070:
1067:
1064:
1061:
1058:
1055:
1052:
1049:
1046:
1043:
1040:
1037:
1034:
1031:
1028:
1025:
1022:
1019:
1016:
1013:
1010:
1007:
1004:
1001:
998:
995:
992:
989:
986:
983:
980:
977:
974:
971:
968:
965:
962:
959:
956:
953:
950:
947:
944:
941:
938:
935:
932:
929:
926:
923:
920:
917:
914:
911:
908:
905:
902:
899:
896:
893:
890:
887:
884:
881:
878:
875:
872:
869:
866:
863:
860:
857:
854:
851:
848:
845:
842:
839:
836:
833:
830:
827:
824:
821:
818:
815:
812:
809:
806:
803:
800:
797:
794:
791:
777:
772:
771:
768:
765:
762:
759:
756:
753:
750:
747:
744:
741:
738:
735:
732:
729:
726:
723:
720:
717:
714:
711:
708:
705:
702:
699:
696:
693:
690:
687:
684:
681:
678:
672:
667:
666:
663:
660:
657:
654:
651:
648:
645:
642:
639:
636:
633:
630:
627:
624:
621:
618:
615:
612:
609:
606:
603:
600:
597:
594:
591:
588:
585:
582:
579:
576:
573:
570:
567:
564:
561:
558:
555:
552:
549:
546:
543:
540:
537:
534:
531:
528:
525:
522:
519:
516:
513:
510:
507:
504:
501:
498:
495:
492:
489:
486:
483:
480:
477:
474:
471:
468:
465:
462:
459:
456:
453:
450:
447:
444:
441:
438:
435:
432:
427:
410:
387:
382:
375:
374:
371:
368:
365:
362:
359:
356:
353:
350:
347:
344:
341:
338:
335:
332:
329:
326:
323:
320:
317:
314:
311:
308:
305:
302:
299:
296:
293:
287:
286:
283:
280:
277:
274:
271:
268:
265:
262:
259:
256:
253:
250:
247:
244:
241:
238:
235:
232:
229:
223:
222:
219:
216:
213:
210:
207:
204:
201:
198:
195:
192:
183:
167:visitor pattern
156:visitor pattern
152:
124:
113:
107:
104:
61:
59:
37:
25:
21:
12:
11:
5:
1294:
1284:
1283:
1269:
1268:
1263:
1257:
1249:
1246:
978:visit_ElementB
948:visit_ElementA
790:
788:
787:
784:
776:
773:
677:
671:
668:
577:visit_ElementB
547:visit_ElementA
436:// Declaration
434:
431:
428:
426:
423:
422:
421:
409:
406:
405:
404:
403:static method.
394:
386:
383:
381:
378:
377:
376:
292:
288:
228:
224:
191:
182:
181:Usage examples
179:
151:
148:
140:design pattern
126:
125:
28:
26:
19:
9:
6:
4:
3:
2:
1293:
1282:
1279:
1278:
1276:
1267:
1264:
1261:
1258:
1255:
1252:
1251:
792:// Definition
785:
782:
781:
780:
675:
481:// Definition
419:
415:
412:
411:
402:
398:
395:
392:
389:
388:
289:
225:
188:
187:
186:
178:
176:
171:
168:
163:
161:
157:
150:Applicability
147:
145:
141:
137:
133:
122:
119:
111:
100:
97:
93:
90:
86:
83:
79:
76:
72:
69: –
68:
64:
63:Find sources:
57:
53:
49:
45:
41:
34:
27:
18:
17:
1146:get_instance
858:get_instance
778:
673:
417:
413:
400:
396:
390:
380:Consequences
184:
172:
165:The regular
164:
153:
135:
129:
114:
105:
95:
88:
81:
74:
62:
1221:getInstance
1176:getInstance
44:independent
930:set_param2
912:set_param1
345:set_param2
327:set_param1
108:March 2019
78:newspapers
52:redirected
1101:instance_
1077:instance_
1059:instance_
1020:instance_
819:instance_
804:protected
493:protected
175:singleton
42:that are
1275:Category
984:ElementB
954:ElementA
888:apply_to
616:apply_to
583:ElementB
553:ElementA
526:apply_to
460:ElementB
451:ElementA
418:apply_to
401:apply_to
363:apply_to
263:apply_to
211:apply_to
1230:param2_
1185:param1_
1119:Element
972:virtual
942:virtual
894:Element
837:param2_
828:param1_
688:Element
622:Element
571:virtual
541:virtual
532:Element
442:Element
294:Element
230:Element
193:Element
144:visitor
92:scholar
56:deleted
1236:param2
1212:param2
1191:param1
1167:param1
1140:accept
1092:return
924:static
906:static
882:static
867:public
849:static
810:static
754:accept
739:param2
733:param1
712:param2
703:param1
652:accept
520:static
505:public
351:param2
333:param1
315:param2
309:param1
281:param2
275:param1
251:param2
245:param1
134:, the
94:
87:
80:
73:
65:
48:merged
1227:->
1182:->
1137:->
1098:->
1074:->
1056:->
795:class
760:&
745:...);
484:class
466:class
457:class
448:class
439:class
138:is a
99:JSTOR
85:books
54:, or
1209:TYPE
1200:void
1164:TYPE
1155:void
1149:());
1134:elem
1125:elem
1110:void
1095:this
1071:this
1065:NULL
1053:this
1026:NULL
975:void
945:void
936:TYPE
927:void
918:TYPE
909:void
885:void
834:TYPE
825:TYPE
748:elem
718:...)
709:TYPE
700:TYPE
694:elem
679:void
646:elem
628:elem
607:void
574:void
544:void
523:void
408:Cons
385:Pros
369:elem
306:TYPE
300:elem
269:elem
242:TYPE
236:elem
217:elem
199:elem
71:news
1089:();
1083:new
879:();
861:();
846:();
763:ssv
727:ssv
658:ssv
640:ssv
517:();
502:();
475:...
130:In
1277::
1224:()
1179:()
1062:==
1047:if
1041:()
1017:::
939:);
921:);
900:);
766:);
661:);
613:::
538:);
372:);
360:::
354:);
342:::
336:);
324:::
284:);
260:::
220:);
208:::
50:,
1242:}
1239:;
1233:=
1218:{
1215:)
1206:(
1197:}
1194:;
1188:=
1173:{
1170:)
1161:(
1152:}
1143:(
1131:{
1128:)
1122:*
1116:(
1107:}
1104:;
1080:=
1068:)
1050:(
1044:{
1035:*
1029:;
1023:=
1011:*
1002:}
999:;
996:0
993:=
990:)
987:*
981:(
969:;
966:0
963:=
960:)
957:*
951:(
933:(
915:(
897:*
891:(
873:~
870::
855:*
840:;
831:;
822:;
816:*
807::
801:{
769:}
757:(
751:.
742:,
736:,
730:(
721:{
715:,
706:,
697:,
691:*
685:(
664:}
655:(
649:.
643:;
634:{
631:)
625:*
619:(
601:}
598:;
595:0
592:=
589:)
586:*
580:(
568:;
565:0
562:=
559:)
556:*
550:(
535:*
529:(
511:~
508::
496::
490:{
472:;
463:;
454:;
445:;
366:(
348:(
330:(
318:;
312:,
303:;
297:*
278:,
272:,
266:(
254:;
248:,
239:;
233:*
214:(
202:;
196:*
121:)
115:(
110:)
106:(
96:·
89:·
82:·
75:·
58:.
36:.
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.