class Invoice{
public void printInvoice(){
System.out.println("this is content");
}
}
class Decorator extends Invoice{
protected Invoice ticket;
public Decorator (Invoice t){
ticket=t;
}
public void printInvoice(){
if(ticket!=null){
ticket.printInvoice();
}
}
}
class HeaderDecorator extends Decorator{
public HeaderDecorator(Invoice t){
super(t);
}
public void printInvoice(){
System.out.println("this is the header");
super.printInvoice();
}
}
class FooterDecorator extends Decorator{
public FooterDecorator(Invoice t){
super(t);
}
public void printInvoice(){
super.printInvoice();
System.out.println("this is the footer");
}
}
public class zhuangshi {
public static void main(String[] args){
Invoice t =new Invoice();
Invoice ticket;
ticket=new FooterDecorator(new HeaderDecorator(t));
ticket.printInvoice();
System.out.println("=====================");
ticket=new FooterDecorator(new HeaderDecorator(new Decorator(null)));
ticket.printInvoice();
}
}
结果
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。