Jako PHP-owiec z 5 dniowym doswiadczeniem z C++ zrobilem cos takiego wg wzorcow ktore mozna spotkac w php. Probowalem sie bawic z szablonami, ale zbyt krotko mam do czynienia z C++ i caly czas pytykam sie na skladni zatem zrobilem cos wg tego co znam z php. Wydaje sie ze to "chodzi". Bede wdzieczny za jakies sugestie zwiazane z optymamizacja tego kodu.
#pragma once
#include <memory>
#include <functional>
#include "Config.h"
#include "Order.h"
class Container
{
private:
Config* config;
Order* order;
std::function<Config*()> setConfig;
std::function<Order*()> setOrder;
public:
Container();
~Container();
Config* getConfig();
Order* getOrder();
};
#include "stdafx.h"
#include "Container.h"
Container::Container()
{
this->setConfig = [this]() -> Config*
{
this->config = new Config();
return this->config;
};
this->setOrder = [this]() -> Order*
{
this->order = new Order(this->setConfig());
return this->order;
};
}
Container::~Container()
{
}
Config* Container::getConfig()
{
if (this->config) {
return this->config;
}
return this->setConfig();
}
Order* Container::getOrder()
{
if (this->order) {
return this->order;
}
return this->setOrder();
}