3
3
import com .sprint .mission .discodeit .menu .ChannelMenu ;
4
4
import com .sprint .mission .discodeit .menu .MessageMenu ;
5
5
import com .sprint .mission .discodeit .menu .UserMenu ;
6
+ import com .sprint .mission .discodeit .repository .ChannelRepository ;
7
+ import com .sprint .mission .discodeit .repository .MessageRepository ;
8
+ import com .sprint .mission .discodeit .repository .UserRepository ;
9
+ import com .sprint .mission .discodeit .repository .file .FileChannelRepository ;
10
+ import com .sprint .mission .discodeit .repository .file .FileMessageRepository ;
11
+ import com .sprint .mission .discodeit .repository .file .FileUserRepository ;
12
+ import com .sprint .mission .discodeit .service .ChannelService ;
13
+ import com .sprint .mission .discodeit .service .MessageService ;
14
+ import com .sprint .mission .discodeit .service .UserService ;
15
+ import com .sprint .mission .discodeit .service .basic .BasicChannelService ;
16
+ import com .sprint .mission .discodeit .service .basic .BasicMessageService ;
17
+ import com .sprint .mission .discodeit .service .basic .BasicUserService ;
18
+ import com .sprint .mission .discodeit .service .file .FileChannelService ;
19
+ import com .sprint .mission .discodeit .service .file .FileMessageService ;
20
+ import com .sprint .mission .discodeit .service .file .FileUserService ;
21
+ import com .sprint .mission .discodeit .service .jcf .integration .ChannelIntegration ;
6
22
import com .sprint .mission .discodeit .service .jcf .JCFChannelService ;
7
23
import com .sprint .mission .discodeit .service .jcf .JCFMessageService ;
8
24
import com .sprint .mission .discodeit .service .jcf .JCFUserService ;
25
+ import com .sprint .mission .discodeit .service .jcf .integration .MessageIntegration ;
26
+ import com .sprint .mission .discodeit .service .jcf .integration .UserIntegration ;
9
27
28
+ import java .nio .file .Path ;
29
+ import java .nio .file .Paths ;
10
30
import java .util .Scanner ;
11
31
32
+ // 기존 코드
33
+ //public class JavaApplication {
34
+ // public static void main(String[] args) {
35
+ // Scanner scanner = new Scanner(System.in);
36
+ //
37
+ //// JCF*Service 구현
38
+ //// UserService userService = new JCFUserService();
39
+ //// MessageService messageService = new JCFMessageService();
40
+ //// ChannelService channelService = new JCFChannelService();
41
+ //
42
+ //// File*Service 구현
43
+ // Path userDir = Paths.get(System.getProperty("user.dir"), "data", "users");
44
+ // Path channelDir = Paths.get(System.getProperty("user.dir"), "data", "channels");
45
+ // Path messageDir = Paths.get(System.getProperty("user.dir"), "data", "messages");
46
+ //
47
+ // UserService userService = new FileUserService(userDir);
48
+ // ChannelService channelService = new FileChannelService(channelDir);
49
+ // MessageService messageService = new FileMessageService(messageDir);
50
+ //
51
+ // UserIntegration userIntegration = new UserIntegration(userService, channelService);
52
+ // MessageIntegration messageIntegration = new MessageIntegration(messageService, userService, channelService);
53
+ // ChannelIntegration channelIntegration = new ChannelIntegration(channelService, userService, messageService);
54
+ //
55
+ // while (true) {
56
+ // System.out.println("\n===== MAIN MENU =====");
57
+ // System.out.println("1. 사용자 메뉴");
58
+ // System.out.println("2. 채널 메뉴");
59
+ // System.out.println("3. 메시지 메뉴");
60
+ // System.out.println("0. 종료");
61
+ // System.out.print("번호를 입력하세요: ");
62
+ //
63
+ // String mainChoice = scanner.nextLine();
64
+ //
65
+ // try {
66
+ // switch (mainChoice) {
67
+ // case "1":
68
+ // UserMenu.manageUsers(scanner, userService, userIntegration);
69
+ // break;
70
+ // case "2":
71
+ // ChannelMenu.manageChannels(scanner, channelService, channelIntegration);
72
+ // break;
73
+ // case "3":
74
+ // MessageMenu.manageMessages(scanner, messageService, messageIntegration);
75
+ // break;
76
+ // case "0":
77
+ // System.out.println("종료합니다.");
78
+ // return;
79
+ // default:
80
+ // System.out.println("올바른 번호를 선택하세요.");
81
+ // }
82
+ // } catch (Exception e) {
83
+ // System.out.println("[오류] 메뉴 처리 중 문제가 발생했습니다: " + e.getMessage());
84
+ // }
85
+ // }
86
+ // }
87
+ //}
88
+
12
89
public class JavaApplication {
13
90
public static void main (String [] args ) {
14
- Scanner scanner = new Scanner (System .in );
15
- JCFUserService userService = new JCFUserService ();
16
- JCFMessageService messageService = new JCFMessageService (userService , null );
17
- JCFChannelService channelService = new JCFChannelService (messageService , userService );
91
+ UserRepository userRepository = new FileUserRepository (Paths .get ("data/users" ));
92
+ ChannelRepository channelRepository = new FileChannelRepository (Paths .get ("data/channels" ));
93
+ MessageRepository messageRepository = new FileMessageRepository (Paths .get ("data/messages" ));
94
+
95
+ UserService userService = new BasicUserService (userRepository );
96
+ ChannelService channelService = new BasicChannelService (channelRepository );
97
+ MessageService messageService = new BasicMessageService (messageRepository );
18
98
19
- messageService .setChannelService (channelService );
20
- userService .addChannelService (channelService );
99
+ UserIntegration userIntegration = new UserIntegration (userService , channelService );
100
+ ChannelIntegration channelIntegration = new ChannelIntegration (channelService , userService , messageService );
101
+ MessageIntegration messageIntegration = new MessageIntegration (messageService , userService , channelService );
21
102
103
+ Scanner scanner = new Scanner (System .in );
22
104
while (true ) {
23
105
System .out .println ("\n ===== MAIN MENU =====" );
24
106
System .out .println ("1. 사용자 메뉴" );
25
107
System .out .println ("2. 채널 메뉴" );
26
108
System .out .println ("3. 메시지 메뉴" );
27
109
System .out .println ("0. 종료" );
28
110
System .out .print ("번호를 입력하세요: " );
111
+ String input = scanner .nextLine ();
29
112
30
- String mainChoice = scanner .nextLine ();
31
-
32
- try {
33
- switch (mainChoice ) {
34
- case "1" :
35
- UserMenu .manageUsers (scanner , userService );
36
- break ;
37
- case "2" :
38
- ChannelMenu .manageChannels (scanner , channelService , userService );
39
- break ;
40
- case "3" :
41
- MessageMenu .manageMessages (scanner , messageService , userService , channelService );
42
- break ;
43
- case "0" :
44
- System .out .println ("종료합니다." );
45
- return ;
46
- default :
47
- System .out .println ("올바른 번호를 선택하세요." );
113
+ switch (input ) {
114
+ case "1" -> UserMenu .manageUsers (scanner , userService , userIntegration );
115
+ case "2" -> ChannelMenu .manageChannels (scanner , channelService , channelIntegration );
116
+ case "3" -> MessageMenu .manageMessages (scanner , messageService , messageIntegration );
117
+ case "0" -> {
118
+ System .out .println ("종료합니다." );
119
+ return ;
48
120
}
49
- } catch (Exception e ) {
50
- System .out .println ("[오류] 메뉴 처리 중 문제가 발생했습니다: " + e .getMessage ());
121
+ default -> System .out .println ("올바른 번호를 입력하세요." );
51
122
}
52
123
}
53
124
}
54
- }
125
+ }
126
+
127
+ /*
128
+ JCF*Service, File*Service와 Basic*Service의 차이
129
+ Basic은 저장 로직을 분리해서 서비스에 비즈니스 로직만 위치함
130
+ 구현체를 생성자로 교체 가능해서 확장성이 좋음
131
+ 저장소를 변경하더라도 로직에 영향을 안줌
132
+ */
0 commit comments