
해당 포스팅은 인프런 백기선님의 '리팩토링'을 학습 후 정리한 내용입니다.
(Mysterius Name)
public class StudyDashboard {
private Set<String> usernames = new HashSet<>();
private Set<String> reviews = new HashSet<>();
private void studyReviews(GHIssue issue) throws IOException {
List<GHIssueComment> comments = issue.getComments();
for (GHIssueComment comment : comments) {
usernames.add(comment.getUserName());
reviews.add(comment.getBody());
}
}
public Set<String> getUsernames() {
return usernames;
}
public Set<String> getReviews() {
return reviews;
}
public static void main(String[] args) throws IOException {
GitHub gitHub = GitHub.connect();
GHRepository repository = gitHub.getRepository("whiteship/live-study");
GHIssue issue = repository.getIssue(30);
StudyDashboard studyDashboard = new StudyDashboard();
studyDashboard.studyReviews(issue);
studyDashboard.getUsernames().forEach(System.out::println);
studyDashboard.getReviews().forEach(System.out::println);
}
}
```
/**
* 덧셈을 수행하여 결과를 리턴하는 함수
* @param x
* @param y
* @return int
*/
public int getSumResult(int x, int y){ return x+y; ```

더 많이 사용되는 변수일 수록 그 이름이 더욱 중요해진다.
다이나믹 타입을 지원하는 언어에서는 타입을 이름에 넣기도 하지만, 클린코드에서는 이러한 코드는 클린하지 않은 변수 명으로 정하고 있다.
strServerValue = "local";
intServerValue = 1;
private Set<String> usernames = new HashSet<>();
private Set<String> reviewers = new HashSet<>();
Record 자료 구조: 특정 데이터와 관련있는 필드를 묶어놓은 자료 구조
public class SampleRecord {
private final String name;
private final Integer age;
private final Address address;
public SampleRecord(String name, Integer age, Address address) {
this.name = name;
this.age = age;
this.address = address;
}
public String getName() {
return name;
}
public Integer getAge() {
return age;
}
public Address getAddress() {
return address;
}
}
public record SampleRecord(
String name,
Integer age,
Address address
) {}
public class StudyDashboard {
private Set<StudyReview> studyReviews = new HashSet<>();
/**
* 스터디 리뷰 이슈에 작성되어 있는 리뷰어 목록과 리뷰를 읽어옵니다.
* @throws IOException
*/
private void loadReviews() throws IOException {
GitHub gitHub = GitHub.connect();
GHRepository repository = gitHub.getRepository("whiteship/live-study");
GHIssue issue = repository.getIssue(30);
List<GHIssueComment> reviews = issue.getComments();
for (GHIssueComment review : reviews) {
studyReviews.add(new StudyReview(review.getUserName(), review.getBody()));
}
}
public Set<StudyReview> getStudyReviews() {
return studyReviews;
}
public static void main(String[] args) throws IOException {
StudyDashboard studyDashboard = new StudyDashboard();
studyDashboard.loadReviews();
studyDashboard.getStudyReviews().forEach(System.out::println);
studyDashboard.getStudyReviews().forEach(System.out::println);
}
}
public record StudyReview(String reviewer, String review){
}