# 任务2：封装所有原生类型和字符串

做完`if-else`的清理后，代码应该稍微变得简单了一些，下一步要对付的是“封装所有的原生类型和字符串”一条。这其实也是一条《重构》一书中明文指出的坏味道：基本类型偏执。项目的初始，我们使用各种字符串、数字和布尔值来简单描述系统本无可厚非，但单纯的基本类型并不能完整表达数据的意图和可能的操作，编译器也无法帮助你写出语义正确的程序——一个 int 类型的`hours`参数，完全有可能被传递给一个只能处理`minutes`或者`years`的函数。随着系统演进，数据与操作数据的函数/方法会开始分散在各地，行为代码需要了解越来越多的数据假设和校验……系统的数据流和数据结构将很快变得难以维护。而要建立一个体面的对象体系，享受对象封装带来的好处：更内聚的单元，更可复用的模块，第一步总是先创建出这样的对象来。之后，才能逐步把更多的行为搬移到对象上。

![](/files/-M-Jyd29C5MY-EhWvQqA)

## 你的任务

1. 创建出“题目介绍”一节提及的其中 4 个对象：`Job` / `Employer` / `JobSeeker` / `Resume`
2. 封装对象拥有的字段，不直接暴露`public`字段
3. 消除代码中硬编码的若干字符串（错误信息除外）：`published` / `JReq` / `ATS` 等

## 思考

* 过程中有没有不顺畅的地方？

## 参考

* 《重构 2》3.11 基本类型偏执（Primitive Obsession）
* 《重构 2》7.3 以对象取代基本类型（Replace Primitive with Object）
* 《重构 2》7.5 提炼类（Extract Class）
* 《重构 2》11.3 移除标记参数（Remove Flag Argument）


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ethan-lin.gitbook.io/refactoring/dui-xiang-jian-shen-cao/4-task-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
