# 任务7：添加结构

打扫完周边的战场，`update()`方法虽然仍然复杂，但相比一开始，它已经整洁了一些，终于是时候向它发起战斗的号角。这个时候，我们仍然建议你从大的结构入手，而非马上深入它的细节。这个`update()`方法做了很多事情，充斥着很多细节，其中许多细节我们现在也是一知半解，但把所有层级的嵌套收起来，我们大概会看到下面的结构，就是三个并列的条件判断：

```javascript
export class Item {
  ...

  update() {
    if (!this.isAgedBrie() && !this.isBackstagePass()) { ... } else { ... }
    if (!this.isSulfuras()) { ... }
    if (this.sellIn < 0) { ... }
  }

  ...
}
```

现在，你的任务是通读一下这三段代码，大概理解它们做的事情，然后把每一段提炼成一个方法，用它做的事情给它命名。然后回过头看看，代码的含义是不是更加清晰了？

## 你的任务

Java：

```
git checkout task-7-adding-structure
./gradlew clean build
```

JavaScript：

```
git checkout task-7-adding-structure
npm test
```

1. 将`update()`函数中的三块主要分支逻辑提炼成为函数，用它们做的事情给方法命名
2. 要求小步前进，每一步修改之后马上运行所有测试，确保软件行为不变

## 反思

* 你的命名清晰吗？
* 你有没有其他整理程序结构的思路？
* 尝试体会重构使代码结构自然“浮现”的过程


---

# 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/xiang-jin-mei-gui/10-task-7.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.
