Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
echo "Error: LLM_API_KEY secret is not configured"
exit 1
fi
- uses: presubmit/ai-reviewer@latest
- uses: presubmit/ai-reviewer@v0.2.5

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider YAML indentation and structure for the new presubmit step. The new action uses presubmit/ai-reviewer@v0.2.5; ensure the 'env:' mapping is correctly indented under the step (two-space indentation under the 'uses' line). Mis-indentation could break the workflow.

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_MODEL: "gpt-5-nano"
# LLM_MODEL removed to avoid model-specific schema/validation issues
4 changes: 2 additions & 2 deletions localization/zh-TW/abstract-document/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ tag:

## 解釋

抽象文件模式 (Abstract Document Pattern) 使您能夠處理其他非靜態屬性。此模式使用特性 (trait) 的概念來實現型別安全,並將不同類別的屬性分離為一組介面。
抽象文件模式 (Abstract Document Pattern) 使你能夠處理其他非靜態屬性。此模式使用特性 (trait) 的概念來實現型別安全,並將不同類別的屬性分離為一組介面。

真實世界範例

> 考慮由多個部分組成的汽車。但是,我們不知道特定汽車是否真的擁有所有零件,或者僅僅是零件中的一部分。我們的汽車是動態而且非常靈活的。
> 考慮由多個部分組成的汽車。,我們不知道特定汽車是否真的擁有所有零件,或者僅僅是零件中的一部分。我們的汽車是動態而且非常靈活的。

簡單的說

Expand Down
8 changes: 4 additions & 4 deletions localization/zh-TW/abstract-factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,21 @@ LOGGER.info(kingdom.getKing().getDescription());
```

## 在 Java 中何時使用抽象工廠模式
在 Java 中,當您遇到以下情況時,請使用抽象工廠模式::
在 Java 中,當你遇到以下情況時,請使用抽象工廠模式::

* 系統應與其產品的創建、組合和表示方式無關。

* 您需要用多個產品家族中的其中一個來配置系統
* 你需要用多個產品家族中的其中一個來配置系統

* 必須同時使用一系列相關的產品物件,以強制保持一致性。

* 您希望提供一個產品的類別庫,只暴露它們的介面,而不是它們的實作。
* 你希望提供一個產品的類別庫,只暴露它們的介面,而不是它們的實作。

* 相依物件的生命週期比消費者的生命週期短。

* 相依物件需要使用執行時期的值或參數來建構。

* 您需要在執行時期從一個家族中選擇要使用的產品
* 你需要在執行時期從一個家族中選擇要使用的產品

* 新增新產品或家族時,不應要求修改現有程式碼。

Expand Down
2 changes: 1 addition & 1 deletion localization/zh-TW/actor-model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class App {

## 何時在 Java 中使用 Actor Model 模式
- 建立 **並行或分散式系統**時
- 您希望 **沒有共享的可變狀態**時
- 你希望 **沒有共享的可變狀態**時
- 你需要 **非同步、訊息驅動的通訊**時
- 元件應 **隔離且鬆散耦合**

Expand Down
156 changes: 156 additions & 0 deletions localization/zh-TW/acyclic-visitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
title: Acyclic Visitor
shortTitle: Acyclic Visitor
category: Behavioral
language: zh
tag:
- Extensibility
---

## 目的

允許將新功能新增到現有的類層次結構中,而不會影響這些層次結構,也不會有四人幫訪客模式中那樣迴圈依賴的問題。

## 解釋

真實世界例子

> 我們有一個調變解調器類的層次結構。 需要使用基於過濾條件的外部演算法(是Unix或DOS相容的調變解調器)來訪問此層次結構中的調變解調器。

通俗地說

> 非迴圈訪問者允許將功能新增到現有的類層次結構中,而無需修改層次結構

[WikiWikiWeb](https://wiki.c2.com/?AcyclicVisitor) 上說

> 非迴圈訪客模式允許將新功能新增到現有的類層次結構中,而不會影響這些層次結構,也不會建立四人幫訪客模式中固有的迴圈依賴問題。

**程式示例**

這是調變解調器的層次結構。

```java
public abstract class Modem {
public abstract void accept(ModemVisitor modemVisitor);
}

public class Zoom extends Modem {
...
@Override
public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof ZoomVisitor) {
((ZoomVisitor) modemVisitor).visit(this);
} else {
LOGGER.info("Only ZoomVisitor is allowed to visit Zoom modem");
}
}
}

public class Hayes extends Modem {
...
@Override
public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof HayesVisitor) {
((HayesVisitor) modemVisitor).visit(this);
} else {
LOGGER.info("Only HayesVisitor is allowed to visit Hayes modem");
}
}
}
```

下面我們介紹`調變解調器訪問者`類結構。

```java
public interface ModemVisitor {
}

public interface HayesVisitor extends ModemVisitor {
void visit(Hayes hayes);
}

public interface ZoomVisitor extends ModemVisitor {
void visit(Zoom zoom);
}

public interface AllModemVisitor extends ZoomVisitor, HayesVisitor {
}

public class ConfigureForDosVisitor implements AllModemVisitor {
...
@Override
public void visit(Hayes hayes) {
LOGGER.info(hayes + " used with Dos configurator.");
}
@Override
public void visit(Zoom zoom) {
LOGGER.info(zoom + " used with Dos configurator.");
}
}

public class ConfigureForUnixVisitor implements ZoomVisitor {
...
@Override
public void visit(Zoom zoom) {
LOGGER.info(zoom + " used with Unix configurator.");
}
}
```

最後,這裡是訪問者的實踐。

```java
var conUnix = new ConfigureForUnixVisitor();
var conDos = new ConfigureForDosVisitor();
var zoom = new Zoom();
var hayes = new Hayes();
hayes.accept(conDos);
zoom.accept(conDos);
hayes.accept(conUnix);
zoom.accept(conUnix);
```

程式輸出:

```
// Hayes modem used with Dos configurator.
// Zoom modem used with Dos configurator.
// Only HayesVisitor is allowed to visit Hayes modem
// Zoom modem used with Unix configurator.
```

## 類圖

![alt text](./etc/acyclic-visitor.png "Acyclic Visitor")

## 適用性

以下情況可以使用此模式:

* 需要在現有層次結構中新增新功能而無需更改或影響該層次結構時。
* 當某些功能在層次結構上執行,但不屬於層次結構本身時。 例如 ConfigureForDOS / ConfigureForUnix / ConfigureForX問題。
* 當你需要根據物件的型別對物件執行非常不同的操作時。
* 當訪問的類層次結構將經常使用元素類的新派生進行擴充套件時。
* 當重新編譯,重新連結,重新測試或重新分發派生元素非常昂貴時。

## 結果

好處:

* 類層次結構之間沒有依賴關係迴圈。
* 如果新增了新訪客,則無需重新編譯所有訪客。
* 如果類層次結構具有新成員,則不會導致現有訪問者中的編譯失敗。

壞處:

* 透過證明它可以接受所有訪客,但實際上僅對特定訪客感興趣,從而違反了[Liskov的替代原則](https://java-design-patterns.com/principles/#liskov-substitution-principle)
* 必須為可訪問的類層次結構中的所有成員建立訪問者的並行層次結構。

## 相關的模式

* [Visitor Pattern](https://java-design-patterns.com/patterns/visitor/)

## 鳴謝

* [Acyclic Visitor by Robert C. Martin](http://condor.depaul.edu/dmumaugh/OOT/Design-Principles/acv.pdf)
* [Acyclic Visitor in WikiWikiWeb](https://wiki.c2.com/?AcyclicVisitor)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 136 additions & 0 deletions localization/zh-TW/adapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: Adapter
shortTitle: Adapter
category: Structural
language: zh
tag:
- Gang of Four
---

## 又被稱為
包裝器

## 目的
將一個介面轉換成另一個客戶所期望的介面。介面卡讓那些本來因為介面不相容的類可以合作無間。

## 解釋

現實世界例子

> 考慮有這麼一種情況,在你的儲存卡中有一些照片,你想將其傳到你的電腦中。為了傳送資料,你需要某種能夠相容你電腦介面的介面卡以便你的儲存卡能連上你的電腦。在這種情況下,讀卡器就是一個介面卡。
> 另一個例子就是註明的電源介面卡;三腳插頭不能插在兩腳插座上,需要一個電源介面卡來使其能夠插在兩腳插座上。
> 還有一個例子就是翻譯官,他翻譯一個人對另一個人說的話。

用直白的話來說

> 介面卡模式讓你可以把不相容的物件包在介面卡中,以讓其相容其他類。

維基百科中說

> 在軟體工程中,介面卡模式是一種可以讓現有類的介面把其作為其他介面來使用的設計模式。它經常用來使現有的類和其他類能夠工作並且不用修改其他類的原始碼。

**程式設計樣例(物件介面卡)**

假如有一個船長他只會划船,但不會航行。

首先我們有介面`RowingBoat`和`FishingBoat`

```java
public interface RowingBoat {
void row();
}

@Slf4j
public class FishingBoat {
public void sail() {
LOGGER.info("The fishing boat is sailing");
}
}
```
船長希望有一個`RowingBoat`介面的實現,這樣就可以移動

```java
public class Captain {

private final RowingBoat rowingBoat;
// default constructor and setter for rowingBoat
public Captain(RowingBoat rowingBoat) {
this.rowingBoat = rowingBoat;
}

public void row() {
rowingBoat.row();
}
}
```

現在海盜來了,我們的船長需要逃跑但是隻有一個漁船可用。我們需要建立一個可以讓船長使用其划船技能來操作漁船的介面卡。

```java
@Slf4j
public class FishingBoatAdapter implements RowingBoat {

private final FishingBoat boat;

public FishingBoatAdapter() {
boat = new FishingBoat();
}

@Override
public void row() {
boat.sail();
}
}

```

現在 `船長` 可以使用`FishingBoat`介面來逃離海盜了。

```java
var captain = new Captain(new FishingBoatAdapter());
captain.row();
```

## 類圖
![alt text](./etc/adapter.urm.png "Adapter class diagram")


## 應用
使用介面卡模式當

* 你想使用一個已有類,但是它的介面不能和你需要的所匹配
* 你需要建立一個可重用類,該類與不相關或不可預見的類進行協作,即不一定具有相容介面的類
* 你需要使用一些現有的子類,但是子類化他們每一個的子類來進行介面的適配是不現實的。一個物件介面卡可以適配他們父類的介面。
* 大多數使用第三方類庫的應用使用介面卡作為一個在應用和第三方類庫間的中間層來使應用和類庫解耦。如果必須使用另一個庫,則只需使用一個新庫的介面卡而無需改變應用程式的程式碼。

## 後果:
類和物件介面卡有不同的權衡取捨。一個類介面卡

* 適配被適配者到目標介面,需要保證只有一個具體的被適配者類。作為結果,當我們想適配一個類和它所有的子類時,類介面卡將不會起作用。
* 可以讓介面卡重寫一些被適配者的行為,因為介面卡是被適配者的子類。
* 只引入了一個物件,並且不需要其他指標間接訪問被適配者。

物件介面卡

* 一個介面卡可以和許多被適配者工作,也就是被適配者自己和所有它的子類。介面卡同時可以為所有被適配者新增功能。
* 覆蓋被適配者的行為變得更難。需要子類化被適配者然後讓介面卡引用這個子類不是被適配者。


## 現實世界的案例

* [java.util.Arrays#asList()](http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList%28T...%29)
* [java.util.Collections#list()](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#list-java.util.Enumeration-)
* [java.util.Collections#enumeration()](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#enumeration-java.util.Collection-)
* [javax.xml.bind.annotation.adapters.XMLAdapter](http://docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html#marshal-BoundType-)


## 鳴謝

* [Design Patterns: Elements of Reusable Object-Oriented Software](https://www.amazon.com/gp/product/0201633612/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0201633612&linkCode=as2&tag=javadesignpat-20&linkId=675d49790ce11db99d90bde47f1aeb59)
* [J2EE Design Patterns](https://www.amazon.com/gp/product/0596004273/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596004273&linkCode=as2&tag=javadesignpat-20&linkId=48d37c67fb3d845b802fa9b619ad8f31)
* [Head First Design Patterns: A Brain-Friendly Guide](https://www.amazon.com/gp/product/0596007124/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596007124&linkCode=as2&tag=javadesignpat-20&linkId=6b8b6eea86021af6c8e3cd3fc382cb5b)
* [Refactoring to Patterns](https://www.amazon.com/gp/product/0321213351/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0321213351&linkCode=as2&tag=javadesignpat-20&linkId=2a76fcb387234bc71b1c61150b3cc3a7)

```

```
Binary file added localization/zh-TW/adapter/etc/adapter.urm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading