Skip to content
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

[2주차] 객체지향 코드 연습(baaamk) #12

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

baaamk
Copy link

@baaamk baaamk commented Apr 1, 2024

추가 Q & A

🤔 잘 모르겠거나, 더 궁금한 내용이 있었나요?
너무 모르는거 투성이라,,

집중적으로 리뷰 받고싶은 것이 있나요?

Copy link
Member

@Hoya324 Hoya324 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

싱글톤을 시도하시려는 모습이 인상깊네요..! 어느정도 감을 잡으신거 같으니 조금더 클래스 레벨과 메서드 레벨에서 역할과 책임을 나누시고 각 클래스 같에 어떤 협력관계를 이룰 수 있을지 파악해보시면 좋을거 같습니다!
메서드는 클래스 간에 협력하는 메세지라는 것을 이해하신다면 아마 메서드명에 더 신경쓰실 수 있을거라 믿습니다!

return value;
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Setter

public class Account {
protected String accountType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accountType은 private가 아니라 protected인 이유가 있나요?

Comment on lines 19 to 45
private boolean isActivated;
public Account() {
isActivated = true;
accountType = "N";
}
public Account(String accountNumber, String owner, BigDecimal balance){
this();
this.accountNumber = accountNumber;
this.owner = owner;
this.balance = balance;
}
public String getAccountInfo(){
return "계좌 종류:" + accountType + "\n" +
"계좌번호:" + accountNumber + "\n" +
"이름:" + owner + "\n" +
"잔액:" + balance + "\n" +
"활성화:" + isActivated;
}
public BigDecimal withdraw(BigDecimal value) {
this.balance = this.balance.subtract(value);
return value;
}

public BigDecimal deposit(BigDecimal value) {
this.balance = this.balance.add(value);
return value;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드와 메서드 사이에 개행을 추가해주시면 가독성이 더 좋은 코드가 될거 같습니다!

Bank/Bank.java Outdated

public class Bank {
protected static Scanner scanner = new Scanner(System.in);
protected static int seq = 0;//<- 추가되는 계좌 개수
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매직넘버에 대해 한번 알아보시고 0을 INIT_ACCOUNT_NUMBER 과 같은 변수명으로 상수 처리해주시면 더 좋은 코드가 될거 같아요!

https://velog.io/@jeongbeom4693/JAVA-%EC%83%81%EC%88%98-%EB%A7%A4%EC%A7%81-%EB%84%98%EB%B2%84Magic-Number

Bank/Bank.java Outdated
Comment on lines 24 to 39
public void withdraw(){
Account account = null;
System.out.println("출금계좌를 입력하세요.");

String accountNumber = scanner.next();
account = findAccount(accountNumber);
if (account.getAccountType().equals("s")) {
new SavingBank().withdraw((SavingAccount) account);
}
System.out.println("출금 금액을 입력하세요");
BigDecimal value = scanner.nextBigDecimal();
BigDecimal result;
BigDecimal interest = interestCalculators.get(account.getAccountType()).getInterest(account.getBalance());
result = account.withdraw(value);
System.out.println("출금액 %s원과 이자 %s원이 정상적으로 출금되었습니다.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

출금에 대한 역할에 출금계좌 입력, 출금 금액 입력, 출금 결과 반환과 같이 여러가지인 것으로 보입니다! SRP를 지키게 하려면 어떻게 해야할지 한번 고민해보시면 좋을걱 같아요!

https://inpa.tistory.com/entry/OOP-%F0%9F%92%A0-%EC%95%84%EC%A3%BC-%EC%89%BD%EA%B2%8C-%EC%9D%B4%ED%95%B4%ED%95%98%EB%8A%94-SRP-%EB%8B%A8%EC%9D%BC-%EC%B1%85%EC%9E%84-%EC%9B%90%EC%B9%99

private static CentralBank instance = new CentralBank();

private static String BANK_NAME = "중앙은행";
private ArrayList<Account> accountList = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일급 컬렉션에 대해 한번 알아보시면 좋아보이네요!

https://jojoldu.tistory.com/412


// accountList getter/setter <- 중앙은행 인스턴스와 계좌 접근 가능
public ArrayList<Account> getAccountList() {
return accountList;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 accountList를 전달한다면 List의 수정을 막을 수 있을까요? set이 아닌, 즉 의도하지 않은 수정을 만들 수 있을 겁니다!

아래의 자료를 한번 참고해보세요!
https://blog.naver.com/seek316/223325763759

@baaamk baaamk changed the title [1주차] 객체지향 코드 연습(baaamk) [2주차] 객체지향 코드 연습(baaamk) Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants