" + content + "
"; + } + }; + + namespace Client + { + void clientCode(const ExportContext *ctx) + { + std::cout << ctx->exportDocument(); + std::cout << "\n"; + } + } + void run() + { + ExportContext *ctx = new ExportContext{"This is the report content."}; + Client::clientCode(ctx); + + std::cout << " ===HTML Export ===\n"; + ctx->setExportStrategy(new HtmlExportStrategy()); + Client::clientCode(ctx); + + std::cout << " ===JSON Export ===\n"; + ctx->setExportStrategy(new JsonExportStrategy()); + Client::clientCode(ctx); + + delete ctx; + } + } +} + +struct StrategyAutoRunner +{ + StrategyAutoRunner() + { + std::cout << "\n--- Strategy Pattern Example ---\n"; + Strategy::run(); + } +}; + +static StrategyAutoRunner instance; \ No newline at end of file