> For the complete documentation index, see [llms.txt](https://ethan-lin.gitbook.io/refactoring/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ethan-lin.gitbook.io/refactoring/dan-wei-zhuan-huan/index.md).

# 项目导学

## 项目介绍

这个练习是对一道已有实现的“单位转换”题进行重构。题目本身并不算复杂，但我们却从中看到混乱的先兆：混乱的命名、嵌套铺展的`if-else`、可读性较差……通过这个项目，学员可以对重构的核心原理有所了解，并能通过练习掌握小步前进、频繁测试的重构习惯，为后续的重构学习打好基础。

## 教学目标

1. 使学员养成频繁运行测试的习惯
2. 掌握重构基本原理，具备拆分步骤、小步前进的重构能力
3. 在掌握原理的基础上掌握两项最常用的重构手法：方法重命名、提炼方法

## 项目学习时长

5 小时。

* 任务 1：30 min
* 任务 2：30 min
* 任务 3：30 min
* 任务 4：1 h
* 任务 5：1 h
* 任务 6：30 min
* 任务 7：1 h

## 能力目标

* 掌握使用工具运行单元测试的方法
* 理解重构基本原理：十六字心法
* 掌握“函数重命名”重构手法
* 掌握“提炼函数”重构手法
* 熟悉基本的重构快捷键

## 技能目标

* 能使用 IDE 或控制台运行测试
* 能设计或理解重构手法的步骤分解
* 能在 10 秒内完成一次重构操作
* 能使用快捷键加快重构过程


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://ethan-lin.gitbook.io/refactoring/dan-wei-zhuan-huan/index.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
