diff --git a/w9/AI b/w9/AI new file mode 100644 index 0000000..390d39a --- /dev/null +++ b/w9/AI @@ -0,0 +1,14 @@ +3. AI 架构审计(MVC 三层检查) +发送给 AI 的指令模板: +作为 Java 架构审计师,请检查我的 MVC 三层划分是否存在越权行为? + +我的项目结构: +· Model:Article(数据实体)、Storage(数据存取) +· View:ConsoleView(控制台输入输出) +· Controller:CommandController(解析命令、调用 Model) + +请从以下角度审计: +1. View 是否直接调用了 Model 层?(越权) +2. Controller 是否做了 View 的工作?(职责混淆) +3. Model 层是否包含了业务逻辑而非仅仅是数据存取? +4. 各层之间的依赖方向是否正确?(View → Controller → Model) \ No newline at end of file diff --git a/w9/Article.java b/w9/Article.java new file mode 100644 index 0000000..6fe5fe9 --- /dev/null +++ b/w9/Article.java @@ -0,0 +1,27 @@ +import java.util.Date; + +public class Article { + private String title; + private String content; + private String url; + private String author; // 新增 + private Date publishDate; // 新增 + + // 构造器 + public Article(String title, String content, String url, String author, Date publishDate) { + this.title = title; + this.content = content; + this.url = url; + this.author = author; + this.publishDate = publishDate; + } + + // Getters and Setters + public String getAuthor() { return author; } + public void setAuthor(String author) { this.author = author; } + + public Date getPublishDate() { return publishDate; } + public void setPublishDate(Date publishDate) { this.publishDate = publishDate; } + + // 原有字段的 getter/setter... +} \ No newline at end of file diff --git a/w9/Controller.java b/w9/Controller.java new file mode 100644 index 0000000..029bbc9 --- /dev/null +++ b/w9/Controller.java @@ -0,0 +1,8 @@ +public class Controller { + private HistoryCommand history = new HistoryCommand(); + + public void executeCommand(String command) { + history.addCommand(command); // 记录每一条命令 + // ... 原有命令处理逻辑 + } +} \ No newline at end of file diff --git a/w9/HistoryCommand.java b/w9/HistoryCommand.java new file mode 100644 index 0000000..2857540 --- /dev/null +++ b/w9/HistoryCommand.java @@ -0,0 +1,28 @@ +import java.util.ArrayList; +import java.util.List; + +public class HistoryCommand { + private List commandHistory = new ArrayList<>(); + + // 添加命令到历史 + public void addCommand(String command) { + commandHistory.add(command); + } + + // 获取所有历史命令 + public List getHistory() { + return new ArrayList<>(commandHistory); // 返回副本,保护原数据 + } + + // 打印历史记录 + public void printHistory() { + for (int i = 0; i < commandHistory.size(); i++) { + System.out.println((i + 1) + ". " + commandHistory.get(i)); + } + } + + // 清空历史 + public void clear() { + commandHistory.clear(); + } +} \ No newline at end of file