/**
* 装饰模式:
* 1-抽象的构件角色,封装了某种功能
* 2-具体的构件角色,实现抽象的构件角色
* 3-装饰角色,持有抽象构件角色引用并实现抽象的构件角色
* 4-具体的装饰角色,继承装饰角色,增加新的功能
* @author Administrator
*
*/
public interface IComponent
{
void test();
}
//
public class ConcreteComponent implements IComponent
{
@Override
public void test()
{
System.out.println("功能 A");
}
}
public class Decorator implements IComponent
{
private IComponent com;
public Decorator(IComponent com)
{
this.com = com;
}
@Override
public void test()
{
this.com.test();
}
}
public class ConcreteDecorator1 extends Decorator
{
public ConcreteDecorator1(IComponent com)
{
super(com);
}
@Override
public void test()
{
super.test();
this.anotherTtest();
}
public void anotherTtest()
{
System.out.println("功能 C");
}
}