forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontControllerLesson.java
More file actions
44 lines (41 loc) · 1.04 KB
/
Copy pathFrontControllerLesson.java
File metadata and controls
44 lines (41 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package patterns.web;
import java.util.Scanner;
public class FrontControllerLesson {
public static void main(String[] args) {
try(Scanner scanner = new Scanner(System.in)){
while (scanner.hasNext()) {
String nextLine = scanner.nextLine();
new Thread() {
@Override
public void run() {
new DispatcherServlet().process(nextLine);
}
}.start();
}
}
}
}
class DispatcherServlet {
void process(String path) {
switch (path) {
case "home" : new HomeController().show(); break;
case "user" : new UserController().show(); break;
default: new DefaultController().show();
}
}
}
class HomeController {
void show() {
System.out.println("home");
}
}
class UserController {
void show() {
System.out.println("user");
}
}
class DefaultController {
void show() {
System.out.println("error");
}
}