⚡ Build the skills to land top-paying quant jobs. Offer ends in --d --h --m --s-- days -- hours -- minutes -- seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 19d 01h 46m 45s19 days 1 hours 46 minutes 45 seconds.
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;
};