用子类替换类型码

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);
  }

反向操作为 移除子类

别名 用状态/策略替换类型码,提取子类