-
Notifications
You must be signed in to change notification settings - Fork 1
/
BookDescriptionMain.java
44 lines (33 loc) · 1.2 KB
/
BookDescriptionMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package patterns;
import java.util.List;
import java.util.ArrayList;
public class BookDescriptionMain {
public static void main(String [] args) {
BasicBook book = new BasicBook();
//Specify book as Fiction category
FictionBookDecorator fictionBook = new FictionBookDecorator(book);
//Specify that the book has a hard cover
HardCoverDecorator hardCoverBook = new HardCoverDecorator(book);
//What if we want to specify both the category and cover type together
HardCoverDecorator hardCoverFictionBook = new HardCoverDecorator(fictionBook);
//Specify book as Science category
ScienceBookDecorator scienceBook = new ScienceBookDecorator(book);
//What if we want to specify both the category and cover type together
HardCoverDecorator hardCoverScienceBook = new HardCoverDecorator(scienceBook);
//Add all the decorated book items in a list
List<Book> bookList = new ArrayList<Book>() {
{
add(book);
add(fictionBook);
add(hardCoverBook);
add(hardCoverFictionBook);
add(scienceBook);
add(hardCoverScienceBook);
}
};
//Traverse the list to access all the book items
for(Book b: bookList) {
System.out.println(b.describe());
}
}
}