2 changed files with 74 additions and 0 deletions
@ -0,0 +1,36 @@ |
|||||
|
package model; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
public class Article { |
||||
|
private String title; |
||||
|
private String content; |
||||
|
private String url; |
||||
|
// 新增字段
|
||||
|
private String author; |
||||
|
private Date publishDate; |
||||
|
|
||||
|
// 无参构造
|
||||
|
public Article() {} |
||||
|
|
||||
|
// 全参构造(方便赋值)
|
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
// getter & setter
|
||||
|
public String getTitle() { return title; } |
||||
|
public void setTitle(String title) { this.title = title; } |
||||
|
public String getContent() { return content; } |
||||
|
public void setContent(String content) { this.content = content; } |
||||
|
public String getUrl() { return url; } |
||||
|
public void setUrl(String url) { this.url = url; } |
||||
|
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; } |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
package model; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 单例模式:全局唯一记录用户所有输入命令 |
||||
|
*/ |
||||
|
public class HistoryCommand { |
||||
|
// 保存所有命令
|
||||
|
private final List<String> commandList; |
||||
|
|
||||
|
// 单例实例
|
||||
|
private static HistoryCommand instance; |
||||
|
|
||||
|
// 私有构造
|
||||
|
private HistoryCommand() { |
||||
|
commandList = new ArrayList<>(); |
||||
|
} |
||||
|
|
||||
|
// 获取唯一实例
|
||||
|
public static HistoryCommand getInstance() { |
||||
|
if (instance == null) { |
||||
|
instance = new HistoryCommand(); |
||||
|
} |
||||
|
return instance; |
||||
|
} |
||||
|
|
||||
|
// 添加命令
|
||||
|
public void addCommand(String command) { |
||||
|
commandList.add(command); |
||||
|
} |
||||
|
|
||||
|
// 获取所有历史命令
|
||||
|
public List<String> getAllCommand() { |
||||
|
return commandList; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue