Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in --d --h --m --s-- days -- hours -- minutes -- seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 07m 32s1 days 16 hours 7 minutes 32 seconds.
Guide: C++ Interview Questions for HFT and Quant Developer Roles · C++ for Quant Trading: A Step-by-Step Roadmap
A game engine needs to spawn similar entities efficiently without coupling creation logic to concrete types. Examine the implementation below and identify the design pattern being used.
class Entity {
public:
virtual Entity* duplicate() const = 0;
virtual ~Entity() = default;
};
class Enemy : public Entity {
public:
Entity* duplicate() const override { return new Enemy(*this); }
};
class Item : public Entity {
public:
Entity* duplicate() const override { return new Item(*this); }
};
class Spawner {
public:
Spawner(Entity* e, Entity* i) : enemyProto(e), itemProto(i) {}
Entity* spawnEnemy() const { return enemyProto->duplicate(); }
Entity* spawnItem() const { return itemProto->duplicate(); }
private:
Entity* enemyProto;
Entity* itemProto;
};