Replace Type Code with Subclasses

refactorgram

function createEmployee(name, type) {
  return new Employee(name, type);
}

image/svg+xml

function createEmployee(name, type) {
  switch (type) {
    case “engineer”: return new Engineer(name);
    case “salesman”: return new Salesman(name);
    case “manager”:  return new Manager (name);
  }

inverse of Remove Subclass

aliases Replace Type Code with State/Strategy, Extract Subclass