-
Notifications
You must be signed in to change notification settings - Fork 0
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
Java Assignment3 upload by TaehyoungSong #36
base: main
Are you sure you want to change the base?
Conversation
User 클래스 생성자 추가, Electonic 클래스 serialNum++ 를 포함하고 있어 private으로 변경
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.
잘하셨습니다.
정말 꼼꼼하시네요.
혹시 기반 코드가 아래였고, 일부러 태형님이 CompanyName으로 수정하신건가요?
electronicList[i].getCompanyName().equals(company)
특히 CompanyName으로 수정하신거 너무 좋았습니다. 다른 개발자 입장에선 CompanyName과 company를 비교하는 것으로 보일테니 말이죠.
이 경험 꼭 잘 기억하셨으면 좋겠습니다.
싱글톤 생성자 제한은 다시 확인하셨으면 좋겠습니다.
this.companyName = companyName; | ||
this.dateOfMade = dateOfMade; | ||
this.authMethod = authMethod; | ||
} |
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.
생성자 꼼꼼하시네요!!!
productNo를 직접 넣어 생성하는 상황까지 잘 고려해주셨습니다. 👍
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.
생성자를 만드는 기준은 로직상에 생성되는 조건들을 고려하여 생성하면 되는걸까요?
과제에 대한 부분은 일부만 사용하기 떄문에 전체적인 것을 고려하는게 잘 되지 않는 것 같습니다.
생성자를 만드는 기준이 있을까요?
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.
음 질문이 이해가 되지 않습니다.
지금 잘하셨어요.
private String modelName; | ||
private CompanyName companyName; | ||
private LocalDate dateOfMade; | ||
private ArrayList<AuthMethod> authMethod; |
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.
ArrayList의 타입을 ArrayList보다 List를 사용해보세요.
이유가 뭘까요? 어떤 장점이 있을까요?
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.
authMethod 안에 들어가는 내용이 0~4개까지 유동적이기 때문에 ArrayList로 변경을 해서 작성을 해보았습니다.
List로 구현을 했을 경우에 추후에 ArrayList로 변경을 할 수 있으니
List로 선언을 해두는 것이 더 유연하고 확장성이 좋을 듯 하네요.
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.
네 맞아요. 구현체에 변화를 주기 좋은 부분은 상위 타입으로 선언하고 그 타입 안에서 메서드를 사용하면 좋아요.
태형님 말씀대로 구현체를 바꿔도 문제가 없을테니 말이죠.
this(); | ||
this.userId = userId; | ||
this.userPassword = userPassword; | ||
|
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.
이상하게 띄워져 있네요.
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(userId, userPassword, userPhoneNumber, userEmail, userBirthDate, registerTime); | ||
result = 31 * result + Arrays.hashCode(electronicDevices); |
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.
31은 어떤 의미일까요?
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.
31이라는 값이 소수로 자바에서 hashcode를 생성하는데에 고유한 값을 만든다고 실시간 강의에서 하셨던 것 같습니다.
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
구글 링을 해보니 31 이외에도 성능 또는 프로세서와 이유로 다른 소수를 선택하기도 한다고 하네요.
29, 33, 37, 92821 ... 여러 소수들이 프로세서에 따라 속도의 차이가 약간 있는 듯 합니다.
31은 최고의 속도는 아니지만 일정 수준을 보존하는 가성비가 있는 값인 것 같습니다.
import java.util.Arrays; | ||
|
||
public class userTest { | ||
public static void main(String[] args) { |
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.
오오
테스트를 위한 코드를 따로 빼신 것 너무 좋습니다.
일반 Class 내부에 많이들 Main을 넣으셨는데 다 제거 요청드렸거든요. 잘하셨습니다.
* Q. Users 클래스의 객체를 싱글톤으로 생성하는 함수를 작성하시오. | ||
* */ | ||
|
||
final int arrSize = 10; |
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.
이 친구는 priavate 이 아닌 이유가 있을까요?
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.
final이라는 키워드는 더 이상 수정이 불가능하다.
변수의 최종 값이다 정도로 뜻을 알고있는데, 변수를 수정할 수 없다는 건 private과 비슷하지 않나? 라는 생각으로 뺴고 테스트 하다가 빼먹은거 같습니다.. 🤣
다시 생각해보니 해당 클래스에서만 사용되는 배열의 크기에 대한 변수니까 private를 붙히는게 맞는 것 같습니다
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.
final과 private 은 완전히 다른 개념이에요.
헷갈리시면 안돼요~
|
||
public Users() { | ||
|
||
} |
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.
싱글톤을 의도할 때는 생성자를 Private으로 막는게 일반적이에요.
private으로 막고 getInstance()를 사용해! 라고 유도하는거죠.
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.
싱글톤에 대해서 개념이 잘 잡히지 않았던 것 같습니다..
private static Users instance; // 정적 참조 변수
private Users() {
// private 생성자
}
// 객체 변환 정적 메서드
public static Users getInstance() {
if(instance == null){
instance = new Users();
}
return instance;
}
정리하여 다시 잘 알아두겠습니다.
copiedUser.setUserPhoneNumber(user.getUserPhoneNumber()); | ||
copiedUser.setUserEmail(user.getUserEmail()); | ||
copiedUser.setUserBirthDate(user.getUserBirthDate()); | ||
copiedUser.setElectronicDevices(user.getElectronicDevices()); |
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.
프로퍼티가 엄청 많아서 (100개라고 가정해봅시다) 이렇게 하나씩 넣어줬다가 놓치면 어쩌죠??
다른 방법을 한번 찾아보시겠어요?
더 좋은 방식이 없다면 없다는 답변도 좋습니다. 어떤 방법들을 고민했고 왜 다른 것은 별로였다도 좋은 답변이에요.
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.
Cloneable를 사용하여 객체 자체를 .clone() 하는 방법도 한 가지 방법이 될 수 있을까요?
새로운 프로퍼티가 생성되어 한 라인을 계속 생성하는게 생산적이지 않다면 전체를 만드는 새로운 객체로 만들어 복사하는 것이 좋은 방법인 것 같습니다.
Electronic[] companyArray = new Electronic[arrSize]; | ||
int cnt = 0; | ||
for ( int i = 0; i < electronicList.length; i++){ | ||
if (electronicList[i] != null && electronicList[i].getCompanyName().equals(companyName)) { |
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.
오 드디어!!
정말 잘하셨습니다.
실습과제 3번 제출합니다.
질문
빡센 코드리뷰 부탁드립니다!