package com.racoon.util.Design;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class ProxySample extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Service service = new ProxyWorker();
service.shortWork();
service.LongWork();
}
interface Service{
void shortWork();
void LongWork();
}
abstract class DefaultWorker implements Service{
@Override
public void shortWork() {
// TODO Auto-generated method stub
Log.d("Design","간단한 출력");
}
}
class MainWorker extends DefaultWorker{
int i;//무거운거
@Override
public void LongWork() {
// TODO Auto-generated method stub
for(i =0;i<10;i++){
Log.d("Design",String.valueOf(i)+"많은일 ");
}
}
}
class ProxyWorker extends DefaultWorker{
Service HeavyWorker;
@Override
public void LongWork() {
// TODO Auto-generated method stub
HeavyWorker = new MainWorker();
HeavyWorker.LongWork();
}
}
}
'Program > 디자인패턴' 카테고리의 다른 글
observer 패턴 (0) | 2012.10.05 |
---|---|
FacadeSample (0) | 2012.09.05 |
FlyweightSample (0) | 2012.09.05 |
디자인패턴 스터디 1주차 - 추상팩토리,빌더,팩토리메소드 (0) | 2012.08.22 |