-
Notifications
You must be signed in to change notification settings - Fork 248
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
๐ 2๋จ๊ณ - ์๊ฐ์ ์ฒญ(๋๋ฉ์ธ ๋ชจ๋ธ) #627
base: mingulee-devel
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ ํ์ธ์ ๋ฏผ์ ๋ ๐
๋ช๊ฐ์ง ์ฝ๋ฉํธ ๋จ๊ฒจ๋์๋๋ฐ ํ์ธ๋ถํ๋๋ ค์ :)
๊ถ๊ธํ๊ฑฐ๋ ๊ณ ๋ฏผ์ด ๋๋ ๋ถ๋ถ์ด ์์ผ์๋ค๋ฉด ์ธ์ ๋ pr ์ฝ๋ฉํธ ๋๋ dm์ผ๋ก ์์ฒญ ๋ถํ๋๋ฆฝ๋๋ค.
๊ฐ์ฌํฉ๋๋ค ๐โโ๏ธ
|
||
import nextstep.payments.domain.Payment; | ||
|
||
public class FreeSession implements SessionStrategy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Session
์ด๋ผ๋ ๋๋ฉ์ธ์ด ์ด๋ฏธ ์๊ณ ํ์ฌ ๊ตฌํ์ฒด๋ Session์ ๋ฐ๋ฅธ ๊ฒฐ์ ์ ๋ต์ด๊ธฐ ๋๋ฌธ์ ๋ค์ด๋ฐ์ด FreeSessionEnrollStrategy
์ ๊ฐ์ด ์กฐ๊ธ ๋ ๋ช
ํํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์ :)
public void enroll(Payment payment){ //todo | ||
if(canEnroll(payment)){ | ||
payments.add(payment); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canEnroll(Payment payment) { | ||
return !isFull() && payment.isTuitionPaid(tuitionFee); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ตฌ์กฐ๊ฐ ์ด์ํด๋ณด์ด๋ ์ด์ ๋ PaidSessionEnrollStrategy
๋ฅผ ์ด๋ป๊ฒ ํ์ฉํ ๊ฑด์ง ๋ช
ํํ์ง ์์์์ธ ๊ฒ ๊ฐ์์. ์ง๊ธ ์ค๊ณํ ๊ฐ์ฒด์ ์ญํ ๋ก๋ณด๋ฉด,
- ๊ฐ์๊ฐ ๊ฒฐ์ ๊ฐ๋ฅํ ์ํฉ์ธ์ง ํ์ธํด์ค๋ค.
- ์ด๋ฅผ ์ํด ํ์ฌ ์๊ฐ์ ์, ์ต๋ ์๊ฐ์ ์, ๊ฐ์๋ฃ๋ฅผ ๊ฐ์ง๋ค.
- ๊ฒฐ์ ๋ฅผ ๋ฐ์ ์๊ฐ๋ฑ๋กํ๋ค.
๋ผ๊ณ ๋ฐ๋ผ๋ณธ๋ค๋ฉด SessionEnrollStrategy
๋ "์๊ฐ ๋ฑ๋ก"์ด๋ผ๋ ๋ช
์ ๋ง ๋์ํด์ฃผ๋ฉด๋๊ณ , canEnroll์ด ๋์ง ์๋๋ค๋ฉด ์์ธ๋ฅผ ํฐํธ๋ฆฌ๋ ๋ฑ๊ณผ ๊ฐ์ ํ์๋ก ์๊ฐํด๋ณผ ์ ์์ ๊ฒ ๊ฐ์์.
public interface SessionEnrollStrategy {
void enroll(Payment payment);
}
๊ฐ ๋์ด์ผํ๊ณ ,
public class PaidSessionEnrollStrategy {
// ..
public void enroll(Payment payment) {
// canEnroll์ด ์๋ ๊ฒฝ์ฐ ์์ธ
// count๋ฅผ ์ฌ๋ฆฌ๊ณ ๊ฒฐ์ ์ ๋ณด ์ ์ฅ
์ด ๋ ์ ์๊ฒ ์ฃ . ๋ค๋ง ํด๋น ํด๋์ค๋ ์ ๋ต์ผ๋ก ๋ถ๋ฆฌ๊ณ ์๊ธฐ ๋๋ฌธ์ ํผ๋์ ์ค ์ ์๋๋ฐ์. "์ ๋ต"์ด๋ผ๋ ๊ฒ์ ์ด๋ค ํ์๋ฅผ ์ด๋ป๊ฒ ์คํํ๋๋๊ฐ ์ฃผ์ ๊ด์ฌ์ฌ์ด์ง ์ํ๋ฅผ ๋ค๊ณ ๊ด๋ฆฌํ๋ฉด์ ์ ๋ต์ ์ถ๊ตฌํ๋๊ฑด ์ ๋ต์์ฒด์ ์ฑ ์์ ํ์ฅ์์ผ๋ฒ๋ฆด ์ ์์ด์. ์ถ์ํ๋ฅผ ํตํ ์ ๊ทผ์ ๋ง์ง๋ง ์ ๋ต์ด๋๋ ๊ณ ๋ฏผํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค์ :)
public class Sessions { | ||
private List<Session> values; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ฐ์ธ์ ์ผ๋ก ๋จ์ํ ๋ํ๋งํ๋ ํด๋์ค๋ ์ผ๊ธ์ปฌ๋์ ์ผ๋ก ๋ฌถ์ ํ์๋ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ํน์ ๋๋ฉ์ธ ์ฑ ์ ์์ด ๋ฆฌ์คํธ์ด๊ธฐ ๋๋ฌธ์ ์ผ๊ธ์ปฌ๋์ ์ผ๋ก ๋๋ค๋ ๊ฒ์ ๊ณผํ ๋ํ์ด ๋ ์ ์์ด์.
public ImageDimensions(int width, int height) { | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public boolean validDimensions() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ฑ์์์ validation์ ํ์ง ์์ผ์๋ ์ด์ ๊ฐ ์์๊น์? ๊ฐ์ฒด์ ์์ฑ์ ๊ฐ์ฒด๊ฐ ๋ด๋นํ๋ ๊ฒ์ด ๊ฐ์ฒด ์์ฑ์ ์์ ์ฑ์ ๋ณด์ฅํด์ :)
BMP; | ||
|
||
public static boolean validExtension(ImageExtension extension) { | ||
if (!Arrays.asList(GIF, JPG, JPEG, PNG, SVG).contains(extension)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํน์ ํ์ฅ์๋ง ๊ด๋ฆฌํ๊ณ ์ถ๋ค๋ฉด ์์๋ก ๋นผ๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค์ :)
package nextstep.courses.domain.session.coverImage; | ||
|
||
public class ImageSize { | ||
private int size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ถ๋ณ์ผ ์ ์๋ ํ๋๋ค์ ๋ชจ๋ ๋ถ๋ณ์ผ๋ก ์์ ํด์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ :)
|
||
import java.time.LocalDate; | ||
|
||
public class Session { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SessionService
๋ฅผ ํตํด enroll ๋ก์ง์ ๊ตฌํํ๋๊ฒ๊น์ง๊ฐ ๋ฏธ์
์ ์๊ตฌ์ฌํญ์ด์์ :)
private SessionStrategy sessionStrategy; | ||
|
||
public Session(SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionStrategy) { | ||
this(null, null, sessionCoverImage, sessionStatus, sessionStrategy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋๋ค null์ธ ์ผ์ด์ค๋ฅผ ์์ฑ์์์ ์ง์ํ๋ ์ด์ ๊ฐ ์์๊น์?
private FreeSession freeSession; | ||
|
||
@Test | ||
void ์๊ฐ์ ์ฒญ_๊ฐ๋ฅ์ฌ๋ถ_ํ์ธ() { | ||
freeSession = new FreeSession(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ๋๋ค์ ๋ถ๋ณํ๊ฒ ๊ฐ์ ธ๊ฐ์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ :) ๊ฐ๋ณ์ ์ธ ํ๋๋ ๊ฐ๋ณ์ ์ผ ์ ์๋ค๋ผ๋ ์ปจํ ์คํธ๋ฅผ ๊ณ์ ์๊ณ ์ฝ๋๋ฅผ ์ฝ๊ฒ ๋ง๋ค๊ธฐ ๋๋ฌธ์ ๊ฐ๋ฅํ๋ฉด ์ง์ํด์ฃผ์๋ ๊ฒ์ด ์ข์ต๋๋ค.
@Test | ||
void ์๊ฐ์ ์ฒญ_๊ฐ๋ฅ์ฌ๋ถ_ํ์ธ__๊ฐ์_์๊ฐ๋ฃ_ํ์ธ() { | ||
paidSession = new PaidSession(3, 2, 20000); | ||
assertTrue(paidSession.canEnroll(new Payment(20000L))); | ||
paidSession = new PaidSession(3, 2, 20000); | ||
assertFalse(paidSession.canEnroll(new Payment(15000L))); | ||
} | ||
|
||
@Test | ||
void ์๊ฐ์ ์ฒญ_๊ฐ๋ฅ์ฌ๋ถ_ํ์ธ__์ธ์์ด๊ณผ_ํ์ธ() { | ||
|
||
paidSession = new PaidSession(3, 2, 20000); | ||
assertTrue(paidSession.canEnroll(new Payment(20000L))); | ||
paidSession = new PaidSession(2, 2, 20000); | ||
assertFalse(paidSession.canEnroll(new Payment(20000L))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ฐ์ ์ผ๋ก ํ ์คํธ์์ ์ด๋ค๊ฒ์ ํ ์คํธํ๊ณ ์ํ๋์ง๊ฐ ๋ช ํํ์ง ์์ ๊ฒ ๊ฐ์์. ํ ์คํธ๋น ๊ฒ์ฆํ๊ณ ์ํ๋ ๋์์ ๋ช ํํ์ฌ์ผํ๊ณ , ์ด ๊ธฐ์ค์ด ์ด๋ ต๋ค๊ณ ๋๋ผ์ ๋ค๋ฉด assertion์ด ํ๋์ฌ์ผ๋๋ค๊ณ ์๊ฐํด๋ณด์๋ฉด ํธํ ๊ฒ ๊ฐ์์.
์๋ฅผ๋ค๋ฉด ๊ฐ์ ์๊ฐ๋ฃํ์ธ์์ ๊ฒ์ฆํ๊ณ ์ํ๋ ๊ฒ์ canEnroll์ด true์ด๋ค์ธ๋ฐ false์ธ๊ฑธ ํ ์คํธํ ํ์๊ฐ ์์๊น์? ๋ ์ธ์์ด๊ณผ ํ์ธ์ธ๋ฐ canEnroll์ด true์ด๋ค์ธ๊ฑธ ํ ์คํธํ ํ์๊ฐ ์์๊น์?
์๋ ํ์ธ์!
์ง๋๋ฒ์ ํผ๋๋ฐฑ ์ฃผ์ จ๋ ๋ด์ฉ๊ณผ ํจ๊ป 2๋จ๊ณ PR ๋๋ฆฝ๋๋ค
์ง์๋์ด ๋ง์ํด์ฃผ์ ๋๋ก ์ฌ๋ค๋ฆฌ ๊ฒ์์ด ๋๋๊ณ PR๋๋ฆด๊น ํ๋ค๊ฐ ๋ฆฌ๋ทฐ ๊ธฐ๋ค๋ฆฌ๋ ๋์ ์ฌ๋ ค๋ด ๋๋ค!
์๊ตฌ์ฌํญ์ ์ ํ๋๋ก ํ๋ค๊ณ ํ๋๋ฐ ์ ๊ฐ ๊ฐ์ฒด๋ฅผ ์ ๋๋๊ฑด์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค
์ค์ค๋ก ํด๋ณด๊ณ ์ถ์ด์ ์ต๋ํ ๋ค๋ฅธ ๋ถ๋ค์ ์ฝ๋๋ฅผ ํ์ธํ์ง ์๊ณ ํ๋๋ฐ
์ง์ ์ด ์์ด์ PR ๋๋ฆฝ๋๋ค!
ํน์ ๋ณด์๊ณ ํํธ๋ฅผ ์ฃผ์ค ์ ์์๊น์?!
์ฝ๋์์ todo๋ฅผ ๋ฌ์๋์๋๋ฐ์
SessionStrategy๋ฅผ ์์๋ฐ๋ FreeSession์ด๋ PaidSession ๋๋์ด์ PaidSession์ canEnroll์ด true์ผ ๋ payment๋ฅผ ๋ํด์ฃผ๋ ค๊ณ ํ๋๋ฐ ๋ญ๊ฐ ์ด ๋ถ๋ถ์ด ์ด์ํ๊ฒ ๋๊ปด์ง๋๋ค... ๐ข
์ค๋๋ ์ ๋ถํ ๋๋ฆฝ๋๋ค ๐
1๋จ๊ณ ํผ๋๋ฐฑ ๋ฐ์