doWork()
를 호출한다doWork()
를 호출하면 작업을 위임할 Class의 InterfaceWebRequester.class
public interface WebRequester {
void requestHandler();
}
WebClient.class
public class WebClient {
private WebRequester webRequester;
public WebClient(WebRequester webRequester) {
this.webRequester = webRequester;
}
public void doWork() {
webRequester.requestHandler();
}
}
doWork()
) requestHandler()
를 호출한다WebAdapter.class
public class WebAdapter implements WebRequester {
private FancyRequester fancyRequester;
public WebAdapter(FancyRequester fancyRequester) {
this.fancyRequester = fancyRequester;
}
@Override
public void requestHandler() {
fancyRequester.fancyRequestHandler();
}
}
FancyRequester.class
public class FancyRequester {
public void fancyRequestHandler() {
System.out.println("Yay! fancyRequestHandler is called!");
}
}
Main.class
public class Main {
public static void main(String[] args) {
WebAdapter adapter = new WebAdapter(new FancyRequester());
WebClient client = new WebClient(adapter);
client.doWork();
}
}
Yay! fancyRequestHandler is called!
참조: