Skip to content

Commit

Permalink
GameFacade 싱글톤 패턴으로 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
silano08 committed Apr 8, 2024
1 parent aa9307f commit 4e6a500
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/baseball/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
public class Application {

private static final Scanner scanner = new Scanner(System.in); // 전역 Scanner 객체 생성
private static final GameFacade gameFacade = new GameFacade();

public static void main(String[] args) {
// TODO: 프로그램 구현
// start();
// scanner.close(); // 프로그램 종료 시 Scanner 객체 닫기

GameFacade gameFacade = GameFacade.getInstance();
gameFacade.startGame();
}
}
17 changes: 14 additions & 3 deletions src/main/java/facade/GameFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ public class GameFacade {
private static final InputValidator validator = new InputValidator();
private static final ResultCalculator calculator = new ResultCalculator();

public GameFacade() {

// 싱글톤 인스턴스를 저장할 private static 변수
private static GameFacade instance;

// Private 생성자
private GameFacade() {}

// 인스턴스에 접근하기 위한 public static 메소드
public static GameFacade getInstance() {
if (instance == null) {
instance = new GameFacade();
}
return instance;
}


public static void startGame() {
System.out.println("숫자 야구 게임을 시작합니다.\n");
while (true) {
Expand Down Expand Up @@ -46,8 +59,6 @@ public static void startGame() {
public static void onGame(){
String ballNum = generator.computerNum(); // 컴퓨터의 제안 숫자

// System.out.println("디버깅을 위한" + ballNum);

while (true){
System.out.println("숫자를 입력해주세요 :");
// 사용자 입력을 문자열로 받습니다.
Expand Down

0 comments on commit 4e6a500

Please sign in to comment.