Skip to content
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

[미션1]구현 완료했습니다. 리뷰 요청드립니다. #9

Open
wants to merge 2 commits into
base: asong
Choose a base branch
from

Conversation

asong57
Copy link

@asong57 asong57 commented Aug 20, 2020

규칙 중 한 단계의 들여쓰기만 허용한다는 규칙이 있어서 애를 먹었다.
이것을 해결하려고 작은 메소드들을 많이 만들었는데 그러다보니 다른 사람들이 코드를 봤을 때 이해하기가 조금 어려울 수도 있겠다는 생각이 들었다.

평소에는 그냥 한 클래스에 다 해버리는 습관?이 있었는데 이번 미션을 통해서 여러 클래스들로 분리하는 것을 배울 수 있었다.

이번에 객체를 많이 사용하게 되었는데, 전에는 객체를 사용했던 적이 없어서 이것 또한 활용할 수 있게 되었다. 다른 타입이어도 한 번에 묶을 수 있다는 장점을 알게 되었다.

단위 테스트를 만드는 것이 아직 어려운 것 같다.
더 다양한 테스트의 유형들을 찾아 봐야겠다고 느꼈다.

다른 분들이 많이 사용하시는 것 같은 "<>" 요거를 나는 몰라서; 찾아보고 싶다는 생각이 들었다.

description에 이렇게 일기처럼.. 써도 되는건지 모르겠지만...다음 미션에는 더 빠르게 미션을 완료해서 시간을 단축시킬 수 있도록 하겠습니다!

Copy link
Contributor

@hyukjin-lee hyukjin-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

객체지향이 아직 익숙치 않으신 것 같아서 조건을 몇가지 더 드릴게요 전체적으로 고쳐보시면 좋을 것 같습니다 ~
너무너무 고생 많으셨어요 ~

  • RacingGame, Car 는 각자가 잘 알고 있는 정보에 대한 상태를 갖는다 (position, cars, trialCount 등)
  • 배열이 아닌 Collection Framework(List) 를 최대한 활용한다
  • 모든 과제를 정독하고 코드에 최대한 녹여내본다
  • View 에서는 상태를 가지지 않고 static 한 메서드로 구현해본다
  • indent 2를 넘지 않도록 코드를 intellij의 extract method 기능을 사용해서 리팩토링 한다
  • Main, RacingGame, Car, InputView, OutputView 5개의 클래스로 코드를 작성해본다
  • 객체의 상태값은 직접 접근하지 않고 getter, setter 를 통해 접근하는데 setter 사용은 금지하고 생성자를 통해 초기화한다. getter 사용은 지양하되 객체에 행위를 부여해서 값을 이끌어내본다

구현하시다가 궁금한 점 있으시면 언제든 물어보셔도 됩니다 ~

Car.java Outdated
@@ -0,0 +1,4 @@
public class Car {
String name;
int position;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

데이터에 접근제어자가 없으면 어떤 접근제어자가 붙게 될까요?
Car 라는 객체에 행위가 없고 데이터만 담겨있는데 이렇게 구현되면 절차지향과 객체지향의 차이점이 무엇일까요?
데이터에 직접 접근해서 가져다가 쓰면 어떤 문제점이 있을까요?

(구름님의 과제 자료를 한번 더 보시면 좋을 것 같아요~)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

데이터에 접근제어자가 없으면 자동으로 default 접근제어자가 붙게 됩니다.(같은 패키지 내에서만 접근 가능)
객체에 행위가 없으면 기능을 중심으로 구현하는 객체지향이 아닌 데이터를 공유하는 절차지향을 따르게 됩니다.
데이터에 직접 접근해서 가져다가 쓰다보면 코드를 조금 변경하고자 할 때, 코드를 많이 힘들게 수정해야 한다는 단점이 생깁니다. 따라서 기능을 중심으로 메소드를 구현하는 객체지향을 따르면서 구현하는 것이 더 효율적이겠다는 생각이 드네요. 배워갑니다..!

InputView.java Outdated
public String[] inputNames() {
System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)");
String inputNames = scanner.nextLine();
String[] carNames = racing.nameSet(inputNames);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드는 행위(동사) 를 표현해야하므로 setName 이 어떨까요~?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드가 행위(동사)를 표현한다는 점 유의하겠습니다!

InputView.java Outdated
import java.util.Scanner;

public class InputView {
RacingGame racing = new RacingGame();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View 에서 상태를 가지지 않도록 설계해보면 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

설계해보겠습니다!

InputView.java Outdated
public int inputNumber() {
System.out.println("시도할 회수는 몇회인가요?");
int number = scanner.nextInt();
return number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return scanner.nextInt(); 로도 가능하겠네요 ~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요! 불필요한 부분 많이 제거할 수 있도록 해보겠습니다!

Main.java Outdated
String[] carNames = input.inputNames();
int number = input.inputNumber();

ResultView result=new ResultView();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제출전에 code formatting 기능을 사용하시면 좋을 것 같아요~

지난주 피드백 : 줄바꿈, 빈칸 또한 컨벤션이다

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 깜빡하지 않고 code format 하도록 하겠습니다!

RacingGame.java Outdated
import java.util.Random;

public class RacingGame {
public static String[] nameSet(String inputNames) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RacingGame 의 메서드들이 static 이어야 하는 이유가 있을까요?

RacingGame 이 가질 수 있는 상태들이 있을 것 같은데 (cars, try 등)
상태 없이 static 으로 구현하신 이유가 궁금합니다 ~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

절차지향적으로 저도 모르게 구현을 하다보니 그렇게 된 것 같습니다. 객체지향을 좀 더 공부하고 활용해보도록 하겠습니다!

RacingGame.java Outdated
return names;
}
public static String[] nameLengthCheck(String[] names, int i) {
final int MAX_LENGTH = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 상수는 클래스 레벨에서 선언하는게 어떨까요~?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요 수정하도록 하겠습니다!

RacingGame.java Outdated
if (names[i].length() >= MAX_LENGTH) {
System.out.println("자동차의 이름들을 5자 이하로 다시 작성하십시오");
Scanner scanner = new Scanner(System.in);
String inputNames = scanner.nextLine();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View 에서 할 역할을 RacingGame 이라는 도메인 객체에서도 진행하고 있네요~
View 와 역할을 구분해서 의존성을 분리시켜보면 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View와 다른 클래스에서 할 기능들의 분리를 잘 해보도록 하겠습니다!

RacingGame.java Outdated
String[] carNames = nameSet(names);
String cars="";
for(int i=0;i<carNames.length;i++){
cars +=carNames[i]+"";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String 과 StringBuilder, StringBuffer 의 차이점이 무엇일까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String, StringBuilder, StringBuffer 모두 문자열을 저장하고 관리하는 클래스인데, String은 다른 두 클래스와 다른 점은 불변(immutable)하다는 점입니다. 단순한 경우에는 +연산자를 이용하여 합치면 되지만, String객체는 한 번 생성되면 할당된 메모리 공간이 변하지 않으므로 문자열 연산이 많은 경우에는 좋지는 않습니다.
StringBuffer와 StringBuilder는 String과 다르게 문자열 연산으로 기존 객체의 공간이 부족하게 될 때, 기존의 버퍼 크기를 유연하게 늘립니다. 이 두 클래스의 차이점은 StringBuffer는 동기화를 지원하고, StringBuilder는 동기화를 보장하지 않는다는 점입니다.
정리하면 String은 짧은 문자열을 더할 경우 사용하는 것이 좋고,
StringBuffer는 스레드에 안전한 프로그램이 필요할 때 사용하는 것이 좋고,
StringBuilder는 스레드에 안전한지 여부가 전혀 관계없는 프로그램을 개발할 때 사용하면 좋다고 합니다. (단순히 성능을보고 연산이 많은 경우 StringBuilder>StringBuffer>>>String)
하나 또 알아갑니다!

RacingGame.java Outdated
}

public static Car winnerJudge(Car[] c, int max, int i, String winner) {
Car a = new Car();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스터디 규칙 : 변수명을 줄여쓰지 않는다

기억해주시면 감사하겠습니다 ~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명 유의하도록 하겠습니다!

Copy link
Contributor

@hyukjin-lee hyukjin-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드가 훨씬 좋아졌네요 !
고생하셨습니다 ~ 피드백 몇개 또 남겼으니 확인 부탁드려요~

return random.nextInt(10);
}

public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드들이 static 인 이유가 있을까요?

return cars;
}

public static int randomValue() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모든 메서드가 public 으로 공개되어있는 이유가 있을까요?

import java.util.Random;
import java.util.ArrayList;

public class RacingGame {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RacingGame 에서 Cars 에 대한 상태를 들고 있으면 어떨까요?

public class Main {
public static void main(String[] args) {
RacingGame racing = new RacingGame();
ArrayList<Car> cars = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조슈아 블로크의 effective java 에는 '객체는 인터페이스를 사용해 참조하라.'
라는 부분이 있습니다.
한번 읽어보시고 개선해보시면 좋을 것 같아요 ~
jaehun2841.github.io/2019/03/01/effective-java-item64/#%EC%9C%A0%EC%97%B0%ED%95%9C-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EC%9D%84-%EC%83%9D%EC%84%B1%ED%95%98%EB%8A%94-%EC%9D%B8%ED%84%B0%ED%8E%98%EC%9D%B4%EC%8A%A4-%ED%83%80%EC%9E%85-%EB%B3%80%EC%88%98

return winners;
}

public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드명이 대부분 명사인 것 같은데 동사형으로 바꿔보면 어떨까요~
그리고 cnt 같은 경우에도 풀네임으로 적어주면 스터디 규칙상 좋을 것 같습니다

return winners;
}

public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한 클래스에서 책임을 많이 들고 있기 때문에 클래스 길이가 늘어난 것 같은데요,
winner 에 대한 로직을 다른 클래스를 만들어 위임해보면 어떨까요?


public class RacingGameTest {
RacingGame r;
ResultView v;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스터디 규칙 : 변수명을 줄여쓰지 않는다

System.out.println("");
}
ArrayList<String> winners = RacingGame.findWinner(cars);
finalResultView(winners);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResultView 는 어플리케이션의 흐름이나 로직을 알 필요 없이 그냥 들어온 input 에 대해서 출력만 해주는 정도의 역할을 하도록 변경해보면 어떨까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants