📄 teststrategepattern.java
字号:
/**
* use strategy pattern to get price of different books
*
*
*/
public class TestStrategePattern {
private static void getDetails(BookCount book){//use polymorphism
System.out.println("Book " +book.getClass().getName()+"'s price is "+book.getPrice());
System.out.println("Book "+book.getClass().getName() +"'s account is "+book.getAccount());
System.out.println("Book "+book.getClass().getName()+" is sold at price "+book.getBookPrice());
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ABook a = new ABook(0.8,120);
BBook b = new BBook(0.9,100);
CBook c = new CBook(0.7,32);
getDetails(a);
getDetails(b);
getDetails(c);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -