-
Notifications
You must be signed in to change notification settings - Fork 4
Lee ji hyung #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Lee ji hyung #1
Changes from all commits
c6fdd48
e757883
be1f2b7
736b3c8
1f88b31
867f930
6a47bc4
31138c3
0acd4e6
47d75da
1c9db0b
9d0e288
bba77bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,25 @@ | ||
| package legacy; | ||
|
|
||
| import java.util.ArrayList; | ||
| import legacy.service.UserService; | ||
| import legacy.service.UserServiceImpl; | ||
|
|
||
| public class CustomerService { | ||
| ArrayList<CustomerLegacy> customers = new ArrayList<>(); | ||
| UserService userService = new UserServiceImpl(); | ||
|
|
||
| public void run() { | ||
| registerCustomer("101", "홍길동", "ACTIVE"); | ||
| registerCustomer("102", "이순신", "ACTIVE"); | ||
| registerCustomer("103", "강감찬", "ACTIVE"); | ||
| System.out.println("===== 고객 관리 시스템 실행 ====="); | ||
|
|
||
| System.out.println("모든 고객 조회:"); | ||
| listCustomers(); | ||
| userService.addUserData("101", "홍길동", "ACTIVE"); | ||
| userService.addUserData("102", "이순신", "ACTIVE"); | ||
| userService.addUserData("103", "강감찬", "ACTIVE"); | ||
|
|
||
| updateCustomer("101", "홍길순"); | ||
| userService.getAllUserData(); | ||
|
|
||
| deleteCustomer("102"); | ||
| userService.updateUserData("101", "홍길순", "ACTIVE"); | ||
|
|
||
| System.out.println("모든 고객 조회:"); | ||
| listCustomers(); | ||
| } | ||
|
|
||
| public void registerCustomer(String id, String name, String status) { | ||
| CustomerLegacy c = new CustomerLegacy(); | ||
| c.id = id; | ||
| c.name = name; | ||
| c.status = status; | ||
| customers.add(c); | ||
| System.out.println("고객 등록: " + id + ", " + name + ", " + status); | ||
| } | ||
|
|
||
| public void updateCustomer(String id, String newName) { | ||
| for (CustomerLegacy c : customers) { | ||
| if (c.id.equals(id)) { | ||
| System.out.print("고객 정보 수정: "); | ||
| System.out.print("수정 전 - " + c.name); | ||
| c.name = newName; | ||
| System.out.println(", 수정 후 - " + c.name); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void deleteCustomer(String id) { | ||
| for (int i = 0; i < customers.size(); i++) { | ||
| if (customers.get(i).id.equals(id)) { | ||
| customers.remove(i); | ||
| System.out.println("고객 삭제 완료: " + id); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| userService.deleteUserData("102"); | ||
|
|
||
| public void listCustomers() { | ||
| for (CustomerLegacy c : customers) { | ||
| System.out.println("ID: " + c.id + ", 이름: " + c.name + ", 상태: " + c.status); | ||
| } | ||
| userService.getAllUserData(); | ||
| } | ||
| } | ||
|
|
||
| class CustomerLegacy { | ||
| public String id; | ||
| public String name; | ||
| public String status; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package legacy.repository; | ||
|
|
||
| import legacy.vo.User; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public interface UserRepository { | ||
|
|
||
| void addData(User user); | ||
| void updateData(String id, String name, String status); | ||
| void deleteData(String id); | ||
| User getUser(String id); | ||
| ArrayList<User> getUsers(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package legacy.repository; | ||
|
|
||
| import legacy.vo.User; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class UserRepositoryImpl implements UserRepository { | ||
| private ArrayList<User> users = new ArrayList<>(); | ||
|
|
||
| @Override | ||
| public void addData(User user) { | ||
| users.add(user); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateData(String id, String name, String status) { | ||
| for(User data : users){ | ||
| if(data.getId().equals(id)){ | ||
| System.out.print("[INFO] 고객 수정 성공: "); | ||
| String beforeName = data.getName(); | ||
| String beforeStatus = data.getStatus(); | ||
|
|
||
|
|
||
| data.setUser(name, status); | ||
|
|
||
| System.out.print("ID: " + data.getId()); | ||
|
|
||
| if(!beforeName.equals(name)){ | ||
| System.out.print(" | 이름: " + beforeName + " -> " + data.getName()); | ||
| } | ||
| if(!beforeStatus.equals(status)){ | ||
| System.out.print(" | 상태: " + beforeStatus + " -> " + data.getStatus()); | ||
| } | ||
| System.out.println(); | ||
| return; | ||
| } | ||
| } | ||
| System.out.println("해당 id의 고객을 찾을 수 없습니다"); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteData(String id) { | ||
| for(User data : users){ | ||
| if(data.getId().equals(id)){ | ||
| System.out.print("[INFO] 고객 삭제 성공: "); | ||
| System.out.print("ID: " + data.getId() + " | 이름: " + data.getName()); | ||
| System.out.println(); | ||
| users.remove(data); | ||
|
|
||
| return; | ||
| } | ||
| } | ||
| System.out.println("해당 id의 고객을 찾을 수 없습니다"); | ||
| } | ||
|
|
||
| @Override | ||
| public User getUser(String id) { | ||
| for (User data : users) { | ||
| if (data.getId().equals(id)) { | ||
| return data; | ||
| } | ||
| } | ||
| System.out.println("해당 id의 고객을 찾을 수 없습니다"); | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public ArrayList<User> getUsers() { | ||
| return users; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package legacy.service; | ||
|
|
||
| public interface UserService { | ||
|
|
||
|
|
||
| void addUserData(String id, String name, String status); | ||
| void updateUserData(String id, String name, String status); | ||
| void deleteUserData(String id); | ||
| void getAllUserData(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package legacy.service; | ||
|
|
||
| import legacy.repository.UserRepository; | ||
| import legacy.repository.UserRepositoryImpl; | ||
| import legacy.vo.User; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class UserServiceImpl implements UserService { | ||
| UserRepository userRepository = new UserRepositoryImpl(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 또한 마찬가지겠죠? |
||
|
|
||
| @Override | ||
| public void addUserData(String id, String name, String status) { | ||
| User user = new User(id, name, status); | ||
| userRepository.addData(user); | ||
| System.out.println("[INFO] 고객 등록 성공: " + userRepository.getUser(id).toString()); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateUserData(String id, String name, String status) { | ||
| userRepository.updateData(id, name, status); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteUserData(String id) { | ||
| userRepository.deleteData(id); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void getAllUserData() { | ||
| ArrayList<User> users = userRepository.getUsers(); | ||
| System.out.println("----- 고객 조회 결과 -----"); | ||
| System.out.println("총 고객 수: " + users.size()); | ||
| int i = 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 대부분의 변수명은 괜찮았는데 이부분은 조금 아쉽네요. 그리고 번호가 1번부터 시작해야 하는 것으로 아는데 i++ 로 진행하면 0부터 나올 것 같은데 한 번 확인해 보시면 좋을 것 같아요. |
||
| for (User user : users) { | ||
| System.out.print(i++ + ". "); | ||
| System.out.println(user.toString()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package legacy.vo; | ||
|
|
||
| public class User { | ||
| private String id; | ||
| private String name; | ||
| private String status; | ||
|
|
||
| public User(){} | ||
|
|
||
| public User(String id, String name, String status) { | ||
| this.id = id; | ||
| this.name = name; | ||
| this.status = status; | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getStatus() { | ||
| return status; | ||
| } | ||
|
|
||
| public void setUser(String name, String status) { | ||
| this.name = name; | ||
| this.status = status; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| String status; | ||
| if(this.status.equals("ACTIVE")){ | ||
| status = "활성"; | ||
| } | ||
| else{ | ||
| status = "비활성"; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자바를 사용한다면 이런 간단한 조건은 3항 연산을 사용하면 더 깔끔하게 보일 것 같아요! 그리고 toString을 활용한 것이 굉장히 좋아 보입니다! |
||
| return "ID: " + this.id + ", 이름: " + this.name + ", 상태: " + status; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserService를 인터페이스로 추상화 한 것은 매우 좋다고 생각합니다.
그런데 인터페이스의 구현체를 CustomerService 내부에 객체로 생성하면 인터페이스로 추상화 한 이점이 살지 않습니다.
또한 비즈니스 로직같은 상위 모듈은 데이터, 모델 같은 하위 모듈을 직접 참조하면 안됩니다.
객체지향 원칙에는 DIP 라는 것이 있는데 한 번 찾아보시면 도움이 되실 것 같아요.