Factory Functions & Singleton Pattern

What design principle does this factory function follow?
const createGameEntity = (name, type) => {
  // Base entity with common properties
  const entity = {
    name,
    type,
    id: Math.random().toString(36).substr(2, 9),
    createdAt: new Date()
  };
  
  // Add type-specific properties and methods
  if (type === 'player') {
    return {
      ...entity,
      health: 100,
      inventory: [],
      attack(target) { /* implementation */ }
    };
  } else if (type === 'enemy') {
    return {
      ...entity,
      health: 50,
      damage: 10,
      attack(target) { /* implementation */ }
    };
  } else if (type === 'item') {
    return {
      ...entity,
      value: 15,
      use() { /* implementation */ }
    };
  }
  
  // Default case
  return entity;
};
Next Question (25/32)