-
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
[11주차] 09. 데이터 조직화 #10
Labels
Comments
9.1 변수 쪼개기역할 하나당 변수 하나다. IDE에서 특정 심벌이 쓰인 위치를 시각적으로 강조해주는 기능을 사용하면 편하다. 9.2 필드 이름 바꾸기9.3 파생 변수를 질의 함수로 바꾸기9.4 참조를 값으로 바꾸기9.5 값을 참조로 바꾸기갱신되어서는 안되는 값들이 반복되서 쓰일 때 참조로 바꿔준다. 9.6 매직 리터럴 바꾸기리터럴을 상수화 한다. |
느낀 점
|
전반적으로 적용하기 쉽지만 좋은 습관, 중요한 내용이라 생각 9.1 변수 쪼개기// before
float temp = 2 * (height + width);
System.out.println(temp);
temp = height * width;
System.out.println(temp);
// after
float perimeter = 2 * (height + width);
System.out.println(perimeter);
float area = height * width;
System.out.println(area);
9.2 필드이름 바꾸기// before
class Organization {
private final String name;
...
public String name() {return name;}
}
// after
class Organization {
private final String title;
...
public String title() {return title;}
}
9.3 파생 변수를 질의 함수로 바꾸기// before
public void setDiscount(int number) {
int old = this.discount;
this.discount = number;
this.discountedTotal += old - number;
}
public int discountedTotal() {return this.discountedTotal;}
// after
public void setDiscount(int number) {this.discount = number;}
public int discountedTotal() {
return this.baseTotal - this.discount;
}
9.4 참조를 값으로 바꾸기// before
public void applyDiscount(int discountAmount) {
this.price.discount(discountAmount);
}
// after
public void applyDiscount(int discountAmount) {
this.price = new Money(
this.price.amount() - discountAmount,
this.price.currency());
}
9.5 값을 참조로 바꾸기// before
Customer customer = new Customer(customerData);
// after
Customer custormer = customerRepository.get(customerData.id());
9.6 매직 리터럴 바꾸기// before
public float potentialEnergy(float mass, float height) {
return mass * 9.81 * height;
}
// after
private static final float STANDARD_GRAVITY = 9.81;
public float potentialEnergy(float mass, float height) {
return mass * STANDARD_GRAVITY * height;
}
// 번외 before
gender.equals(MALE_GENDER);
// 번외 after
isMale(gender);
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
진도
방식
The text was updated successfully, but these errors were encountered: