-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: main
Are you sure you want to change the base?
Conversation
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.
싱글톤을 시도하시려는 모습이 인상깊네요..! 어느정도 감을 잡으신거 같으니 조금더 클래스 레벨과 메서드 레벨에서 역할과 책임을 나누시고 각 클래스 같에 어떤 협력관계를 이룰 수 있을지 파악해보시면 좋을거 같습니다!
메서드는 클래스 간에 협력하는 메세지라는 것을 이해하신다면 아마 메서드명에 더 신경쓰실 수 있을거라 믿습니다!
Accountfile/Account.java
Outdated
return value; | ||
} | ||
|
||
} |
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.
Accountfile/Account.java
Outdated
@Setter | ||
|
||
public class Account { | ||
protected String accountType; |
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.
accountType은 private가 아니라 protected인 이유가 있나요?
Accountfile/Account.java
Outdated
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; | ||
} |
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.
메서드와 메서드 사이에 개행을 추가해주시면 가독성이 더 좋은 코드가 될거 같습니다!
Bank/Bank.java
Outdated
|
||
public class Bank { | ||
protected static Scanner scanner = new Scanner(System.in); | ||
protected static int seq = 0;//<- 추가되는 계좌 개수 |
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.
매직넘버에 대해 한번 알아보시고 0을 INIT_ACCOUNT_NUMBER 과 같은 변수명으로 상수 처리해주시면 더 좋은 코드가 될거 같아요!
Bank/Bank.java
Outdated
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원이 정상적으로 출금되었습니다."); | ||
} |
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.
출금에 대한 역할에 출금계좌 입력, 출금 금액 입력, 출금 결과 반환과 같이 여러가지인 것으로 보입니다! SRP를 지키게 하려면 어떻게 해야할지 한번 고민해보시면 좋을걱 같아요!
Bank/CentralBank.java
Outdated
private static CentralBank instance = new CentralBank(); | ||
|
||
private static String BANK_NAME = "중앙은행"; | ||
private ArrayList<Account> accountList = new ArrayList<>(); |
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.
일급 컬렉션에 대해 한번 알아보시면 좋아보이네요!
Bank/CentralBank.java
Outdated
|
||
// accountList getter/setter <- 중앙은행 인스턴스와 계좌 접근 가능 | ||
public ArrayList<Account> getAccountList() { | ||
return accountList; |
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.
이렇게 accountList를 전달한다면 List의 수정을 막을 수 있을까요? set이 아닌, 즉 의도하지 않은 수정을 만들 수 있을 겁니다!
아래의 자료를 한번 참고해보세요!
https://blog.naver.com/seek316/223325763759
추가 Q & A
🤔 잘 모르겠거나, 더 궁금한 내용이 있었나요?
너무 모르는거 투성이라,,
집중적으로 리뷰 받고싶은 것이 있나요?