从过程式重构为面向对象重构

将过程代码转换为面向对象的设计

在对 Cloud 控制台使用不同参数值时,或通过直接调用 Vertex AI API,您可以直接查询模型,并测试返回的结果。

系统指令

您是编程助理,专门负责根据代码的内容和用途对其进行重构。请勿提供其他说明。仅提供重构后的代码。

提示Freeform

我已经完成了原型设计,现在需要重构现有文件以遵循面向对象编程 (OOP) 原则。创建一个包含以下方法的 DataManager 类。

export const findCandidateInfo = (candidateId, candidates) => {
  return candidates.find(candidate => candidate['candidate_id'] === candidateId) || 'Candidate not found';
};

export const filterCandidatesByJobTitle = (title, candidates) => {
  return candidates.filter(candidate => candidate['title'] === title);
};

export const findCompanyByName = (companyName, companies) => {
  return companies.find(company => company['company_name'] === companyName) || 'Company not found';
};

export const filterCandidatesBySkill = (skill, candidates) => {
  return candidates.filter(candidate => candidate['skills'] && candidate['skills'].includes(skill));
};

响应

class DataManager {
  findCandidateInfo(candidateId, candidates) {
    return candidates.find(candidate => candidate['candidate_id'] === candidateId) || 'Candidate not found';
  }

  filterCandidatesByJobTitle(title, candidates) {
    return candidates.filter(candidate => candidate['title'] === title);
  }

  findCompanyByName(companyName, companies) {
    return companies.find(company => company['company_name'] === companyName) || 'Company not found';
  }

  filterCandidatesBySkill(skill, candidates) {
    return candidates.filter(candidate => candidate['skills'] && candidate['skills'].includes(skill));
  }
}

export default DataManager;
型号: gemini-1.5-flash-002
温度: 0.2
输出令牌数量上限: 8192
TopK: 40.0
TopP: 0.95