장식기 모드 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();
	}
}

좋은 웹페이지 즐겨찾기