[스프링부트] 3. 디스패처

백하림's avatar
Mar 13, 2025
[스프링부트] 3. 디스패처
💡
새로운 기능을 추가하고 싶으면 A회사에 전화해서 만들어달라고 요청해야 함 (불편)
package ex01; import java.util.Scanner; interface Controller { void login(); void join(); void logout(); } // 1. A회사 class Dispatcher { Controller controller; public Dispatcher(Controller controller) { this.controller = controller; } public void routing(String path) { if (path.equals("/login")) { controller.login(); } else if (path.equals("/join")) { controller.join(); } else if (path.equals("/logout")) { controller.logout(); } } } // 2. B회사 (구매할게 - Controller 구현해서 만들어) // 새로운 기능을 추가하고 싶으면 A회사에 전화해서 만들어달라고 요청해야 함 (불편) class UserController implements Controller { @Override public void login() { System.out.println("Login call"); } @Override public void join() { System.out.println("Join call"); } @Override public void logout() { System.out.println("Logout call"); } } public class App { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String path = sc.nextLine(); UserController uc = new UserController(); Dispatcher ds = new Dispatcher(uc); ds.routing(path); } }
notion image
notion image
notion image
 
Share article

harimmon