refactoring : duplicated code - pull up method

This commit is contained in:
haerong22
2022-02-16 01:34:55 +09:00
parent 5eb3995dc8
commit 23da005132
3 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package com.example.refactoring._02_duplicated_code._06_pull_up_method;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
// 중복되는 코드를 상위 클래스로 이동
public class Dashboard {
public static void main(String[] args) throws IOException {
ReviewerDashboard reviewerDashboard = new ReviewerDashboard();
reviewerDashboard.printReviewers();
ParticipantDashboard participantDashboard = new ParticipantDashboard();
participantDashboard.printUsernames(1);
}
public void printUsernames(int eventId) throws IOException {
// Get github issue to check homework
GitHub gitHub = GitHub.connect();
GHRepository repository = gitHub.getRepository("haerong22/Study");
GHIssue issue = repository.getIssue(eventId);
// Get participants
Set<String> participants = new HashSet<>();
issue.getComments().forEach(c -> participants.add(c.getUserName()));
// Print participants
participants.forEach(System.out::println);
}
}

View File

@@ -0,0 +1,5 @@
package com.example.refactoring._02_duplicated_code._06_pull_up_method;
public class ParticipantDashboard extends Dashboard {
}

View File

@@ -0,0 +1,10 @@
package com.example.refactoring._02_duplicated_code._06_pull_up_method;
import java.io.IOException;
public class ReviewerDashboard extends Dashboard {
public void printReviewers() throws IOException {
super.printUsernames(1);
}
}