Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions java-basic/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import model.Student;

public class Main {
public static void main(String[] args) {
Student s1 = new Student("김멋사","20260001","Software");
Student s2 = new Student("김동사","20250001","Hardware");
Student s3 = new Student("김수사","20240001","AI");

Student[] students = {s1,s2,s3};

Student.printAll(students);

Comment on lines +5 to +12
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

로직을 깔끔하게 잘 작성하신 것 같습니다!
해당 로직이 Main 클래스에 있다는 점에 대해 한번 생각해보시면 좋을 것 같습니다.
Main 클래스의 역할은 뭘까요? 민구님의 의견 편하게 말씀해주세요!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

main에는 최소한의 코드가 있어야하고 실행을 담당하는 클래스라고 생각하고 있습니다.
레이어드 아키텍처 학습 후에 더욱 구조화 해보도록 하겠습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

실행을 담당하는 클래스를 따로 두고 (예를 들어 run class나 메서드) main 클래스는 해당 실행 메서드를 호출하는 역할로 작성한다면 민구님이 설계하신 "main 클래스는 최소한의 코드가 있어야 한다" 라는 부분을 더 강조할 수 있을 것 같습니다.
구현 방법에 대해 다양하게 고민해보시면 좋을 것 같아요!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

https://wikidocs.net/160947
해당 사이트의 SbbApplication.java 클래스 코드를 보시면 이해가 좀 더 쉬울 것 같아서 보내드립니다😊




}
}
30 changes: 30 additions & 0 deletions java-basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 과제명
java-basic (2주차 과제)

## ⚙️ 실행 방법
### 1. 터미널(Terminal)에서 명령어로 실행
**1단계: 컴파일 (Compile)**
```bash
javac -d out java-basic/Main.java java-basic/model/Student.java
```
**2단계: 실행**
```bash
java -cp out Main
```
## 💡 작업 내용
### 1. `java-basic/model/Student.java`
- **역할**: 학생 정보를 저장하고 관리하는 **Student** 클래스입니다.
- **주요 내용**:
- 학생의 속성(이름, 학번, 전공 등)을 필드로 정의
- 생성자를 통한 데이터 초기화
- 학생 정보를 출력하는 메서드 포함

### 2. `java-basic/Main.java`
- **역할**: 프로그램 실행
- **주요 내용**:
- `Student` 클래스의 인스턴스(객체) 생성
- 생성된 객체의 메서드를 호출하여 콘솔에 데이터 출력 및 확인

## 🤔 느낀 점 / 어려웠던 점
-java 문법을 되새기는 시간을 가지게 된것 같습니다.
-객체 지향 부분을 더욱 심도있게 학습해야할것 같습니다.
22 changes: 22 additions & 0 deletions java-basic/model/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package model;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Student 클래스를 model 폴더에 작성하신 부분이 인상 깊었습니다.
혹시 폴더명을 model로 하신 이유에 대해 알 수 있을까요?
domain 이나 Student 등 폴더 이름을 여러가지로 지을 수 있을텐데 model로 작성하신 이유가 궁금해서요!
패키지 구조와 폴더의 의미와 역할에 대해 찾아보시면 더욱 좋을 것 같습니다😊 ( 혹시 감이 잘 안 오신다면 MVC 패턴 , 레이어드 아키텍처에 대해 찾아보시면 금방 의미를 아실 수 있을 것 같습니다 ㅎㅎ)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

model은 class를 넣어둔다고 생각해서 model 폴더에 넣어두었습니다.
mvc 패턴과 레이어드 아키텍처에 대해 더욱 학습해 보겠습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

패키지 구조는 추후 TDD 또는 DDD 설계에 사용될 개념이기 때문에 미리 학습하시고 넘어가면 좋을 것 같습니다.
공부하신 내용을 개발 블로그로 정리해서 업데이트하시면 더욱 좋을 것 같아요!


public class Student{
private String name;
private String studentId;
private String major;
Comment on lines +4 to +6
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

객체의 정보를 저장하는 필드네요! private로 작성하여 외부에서 접근이 불가능하게 하신 점 정말 잘 하신 것 같습니다.
해당 변수들을 외부에서 수정할 수 없도록 해야하는 이유는 뭘까요? 외부에서 수정 가능하게 한다면 코드량을 늘리지 않고 외부 클래스에서 쉽게 수정할 수 있을텐데 말이죠... 민구님의 생각이 궁금합니다 😄

또한 studentId를 String으로 선언하신 이유가 있을까요? Id 경우 정수형으로 선언해도 될텐데 String으로 선언하신 이유가 궁금하네요!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

외부에서 접근을 막아 무결성을 유지하기 위해서 라고 생각합니다.
만약 외부에서 접근해서 바꿔버리면 코드에 오류가 생길 수 있기 때문이라고 생각합니다.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

studentId를 String으로 한 이유는 만약 0으로 시작 할 경우 int로 하면 0이 손실되기 떄문에 데이터를 보존할려고 String을 사용했습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

private 경우 OOP 원칙과 연관지어서 공부하시면 더 개념이 풍부해지실 것 같습니다. 상속과 캡슐화 관점에서 private 사용 이유를 고민해보시면 좋을 것 같아요



public Student(String name,String studentId,String major){
this.name = name;
this.studentId = studentId;
this. major = major;
}
// 출력 메소드
public static void printAll(Student[] students){
for(Student student : students){
System.out.printf("이름:%s 학번:%s 전공:%s\n",student.name,student.studentId,student.major);
}
}

Comment on lines +14 to +20
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

이름 학번 전공을 순차적으로 출력하는 함수로 출력 기능을 담당하고 있네요
해당 메소드가 Student 클래스 안에 있는 이유를 알 수 있을까요?
지금 student 클래스는 정보를 저장하는 기능과 출력하는 기능을 가지고 있는데 SOLID 원칙 중 단일 책임 원칙을 생각해보면 어떨까요?
레이어를 나눠서 입출력을 담당하는 클래스 , 핵심 로직을 담당하는 클래스 , 정보를 저장하는 클래스 등으로 책임을 나눠 SOLID 원칙을 고려한 설계 패턴을 도입해보는 건 어떨까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

main클래스에 최소한 코드만 두고 싶어 student 클래스에 넣어두었습니다.
SOLID 원칙을 학습후 SOLID 원칙을 적용해 보겠습니다.


}