中文版提示词
请扮演资深软件架构师,对以下代码进行功能等价重构。要求:

  • 遵循 DRY(不要重复自己)原则,抽取公共逻辑,消除重复代码。

  • 将过深的 if-else 嵌套改为早返回(Early Return)或策略模式,提升可读性。

  • 优化变量、函数与类命名,使其具有自解释性(Self-Documenting)。

  • 最后,请用表格列出重构前后的对比差异,突出改动点与收益。

请提供编程语言并粘贴代码块。直接输出重构后的代码、对比表格及简要说明,无需其他内容。


英文版提示词(English Version Prompt)
Please act as a senior software architect to refactor the following code while preserving its functionality. Requirements:

  • Follow the DRY (Don’t Repeat Yourself) principle by extracting common logic and eliminating duplicate code.

  • Replace deeply nested if-else statements with Early Return or Strategy Pattern to improve readability.

  • Rename variables, functions, and classes to make them self‑documenting and intention‑revealing.

  • Finally, provide a comparison table showing the differences before and after refactoring, highlighting changes and benefits.

Please specify the programming language and paste the code block. Output directly the refactored code, comparison table, and a brief explanation, without any other content.