You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1008 B
37 lines
1008 B
package jichuti1;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 图书类别类,与图书建立聚合关系
|
|
*/
|
|
public class BookCategory {
|
|
private String categoryId; // 类别ID
|
|
private String categoryName; // 类别名称
|
|
private List<Book> books; // 聚合的图书列表
|
|
|
|
public BookCategory(String categoryId, String categoryName) {
|
|
this.categoryId = categoryId;
|
|
this.categoryName = categoryName;
|
|
this.books = new ArrayList<>();
|
|
}
|
|
|
|
// 添加图书到类别
|
|
public void addBook(Book book) {
|
|
if (!books.contains(book)) {
|
|
books.add(book);
|
|
}
|
|
}
|
|
|
|
// 移除类别中的图书
|
|
public void removeBook(Book book) {
|
|
books.remove(book);
|
|
}
|
|
|
|
// getter和setter
|
|
public String getCategoryId() { return categoryId; }
|
|
public String getCategoryName() { return categoryName; }
|
|
public List<Book> getBooks() { return new ArrayList<>(books); }
|
|
}
|