Design Pattern Examples
Overview of object-oriented design patterns
c/Visitor_Exercise.h File Reference

Declaration of the Visitor_Exercise() function as used in the Visitor Pattern. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __VISITOR_EXERCISE_H__
 

Functions

void Visitor_Exercise (void)
 Example of using the Visitor Pattern.
 

Detailed Description

Declaration of the Visitor_Exercise() function as used in the Visitor Pattern.

Definition in file c/Visitor_Exercise.h.

Macro Definition Documentation

◆ __VISITOR_EXERCISE_H__

#define __VISITOR_EXERCISE_H__

Definition at line 9 of file c/Visitor_Exercise.h.

Function Documentation

◆ Visitor_Exercise()

void Visitor_Exercise ( void  )

Example of using the Visitor Pattern.

The Visitor pattern is used to add functionality to a list of otherwise unchanging element objects by passing a visitor object to each element object. Each element object calls the visitor object, passing itself as an argument. The visitor object then does something based on the type of the element.

In this exercise, a collection of shop objects is initialized then an order visitor is created to retrieve an item from one of the shop objects. Along the way, shops that don't have the necessary ingredients use another order visitor to order ingredients from other shops. This approach assumes no two shops sell the same thing.

Definition at line 37 of file Visitor_Exercise.c.

References ConstStringList_AddString(), OrderVisitor::ItemsReceived, OrderVisitor::ItemsToOrder, Village::Name, OrderVisitor_Clear(), OrderVisitor_Initialize(), OrderVisitor::ShopNameReceivedFrom, _ConstStringList::strings, _ConstStringList::strings_count, Village_Clear(), Village_Initialize(), Village_Load(), and Village_VisitShop().