장식기 모드 decorator
2092 단어 장식기 모드
package mode.decorator;
/**
*
* , 。
*
* 。 , Sourcable
*
* */
public interface Sourcable {
public void operation();
}
package mode.decorator;
/**
*
* Sourcable , Sourcable Sourcable
*
* operation Sourcable operation , ,
*
* */
public class Decorator1 implements Sourcable {
private Sourcable sourcable;
public Decorator1(Sourcable sourcable) {
super();
this.sourcable = sourcable;
}
@Override
public void operation() {
System.out.println(" ");
this.sourcable.operation();
System.out.println(" ");
}
}
package mode.decorator;
/**
*
* Sourcable , Sourcable Sourcable
*
* operation Sourcable operation , ,
*
* */
public class Decorator2 implements Sourcable {
private Sourcable sourcable;
public Decorator2(Sourcable sourcable) {
super();
this.sourcable = sourcable;
}
@Override
public void operation() {
System.out.println(" ");
sourcable.operation();
System.out.println(" ");
}
}
package mode.decorator;
/**
*
* Sourcable , Sourcable Sourcable
*
* operation Sourcable operation , ,
*
* */
public class Decorator3 implements Sourcable {
private Sourcable sourcable;
public Decorator3(Sourcable sourcable) {
super();
this.sourcable = sourcable;
}
public void operation() {
System.out.println(" ");
sourcable.operation();
System.out.println(" ");
}
}
package mode.decorator;
/**
*
* , Sourcable , operation
*
* */
public class Source implements Sourcable {
@Override
public void operation() {
System.out.println(" ");
}
}
테스트
package mode.decorator;
public class Test {
public static void main(String[] args) {
Sourcable source = new Source();
//
Sourcable obj = new Decorator1(new Decorator2(new Decorator3(source)));
obj.operation();
}
}