-
Notifications
You must be signed in to change notification settings - Fork 14
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차 과제 제출 #12
Open
shinyj0
wants to merge
7
commits into
IT-Cotato:develop
Choose a base branch
from
shinyj0:shinyj0
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[신예진] 1차 과제 제출 #12
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
887b58e
feat: 로직 분리
shinyj0 0387650
feat: conjured 추가
shinyj0 d98361a
refactor: 매직넘버 관리
shinyj0 b4ef690
Revert "refactor: 매직넘버 관리"
shinyj0 7d888ef
refactor: 매직넘버 관리
shinyj0 a3f0a71
refactor: 인터페이스를 추상클래스로 변경, 공통함수 작성
shinyj0 c6f1cbd
chore: 주석 추가
shinyj0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,21 @@ | ||
package com.gildedrose; | ||
|
||
import com.gildedrose.update.UpdateLogic; | ||
import com.gildedrose.update.UpdateLogicFactory; | ||
|
||
class GildedRose { | ||
Item[] items; | ||
UpdateLogicFactory updateLogicFactory; | ||
|
||
public GildedRose(Item[] items) { | ||
this.items = items; | ||
updateLogicFactory = new UpdateLogicFactory(); | ||
} | ||
|
||
public void updateQuality() { | ||
for (int i = 0; i < items.length; i++) { | ||
if (!items[i].name.equals("Aged Brie") | ||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { | ||
if (items[i].quality > 0) { | ||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { | ||
items[i].quality = items[i].quality - 1; | ||
} | ||
} | ||
} else { | ||
if (items[i].quality < 50) { | ||
items[i].quality = items[i].quality + 1; | ||
|
||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { | ||
if (items[i].sellIn < 11) { | ||
if (items[i].quality < 50) { | ||
items[i].quality = items[i].quality + 1; | ||
} | ||
} | ||
|
||
if (items[i].sellIn < 6) { | ||
if (items[i].quality < 50) { | ||
items[i].quality = items[i].quality + 1; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { | ||
items[i].sellIn = items[i].sellIn - 1; | ||
} | ||
|
||
if (items[i].sellIn < 0) { | ||
if (!items[i].name.equals("Aged Brie")) { | ||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { | ||
if (items[i].quality > 0) { | ||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { | ||
items[i].quality = items[i].quality - 1; | ||
} | ||
} | ||
} else { | ||
items[i].quality = items[i].quality - items[i].quality; | ||
} | ||
} else { | ||
if (items[i].quality < 50) { | ||
items[i].quality = items[i].quality + 1; | ||
} | ||
} | ||
} | ||
for (Item item : items) { | ||
UpdateLogic updateLogic = updateLogicFactory.getUpdateLogic(item); | ||
updateLogic.update(item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.gildedrose.update; | ||
|
||
import static com.gildedrose.update.ItemConstants.*; | ||
|
||
import com.gildedrose.Item; | ||
|
||
public class AgedBrie extends UpdateLogic { | ||
|
||
@Override | ||
public void update(Item item) { | ||
|
||
increaseQuality(item, DEFAULT_QUALITY_INCREMENT); | ||
decreaseSellIn(item); | ||
|
||
if (item.sellIn < QUALITY_MIN) { | ||
increaseQuality(item, DEFAULT_QUALITY_INCREMENT); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Java/src/main/java/com/gildedrose/update/BackstagePass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.gildedrose.update; | ||
|
||
import static com.gildedrose.update.ItemConstants.*; | ||
|
||
import com.gildedrose.Item; | ||
|
||
public class BackstagePass extends UpdateLogic { | ||
|
||
private static final int BACKSTAGE_SELL_IN_THRESHOLD_10 = 10; | ||
private static final int BACKSTAGE_SELL_IN_THRESHOLD_5 = 5; | ||
|
||
@Override | ||
public void update(Item item) { | ||
|
||
// 판매 기한이 10일 이하일 때 품질 1 증가 | ||
if (item.sellIn <= BACKSTAGE_SELL_IN_THRESHOLD_10) { | ||
increaseQuality(item, DEFAULT_QUALITY_INCREMENT); | ||
} | ||
|
||
// 판매 기한이 5일 이하일 때 추가로 품질 1 증가 | ||
if (item.sellIn <= BACKSTAGE_SELL_IN_THRESHOLD_5) { | ||
increaseQuality(item, DEFAULT_QUALITY_INCREMENT); | ||
} | ||
|
||
// 판매 기한 1일 감소 | ||
decreaseSellIn(item); | ||
|
||
// 판매 기한이 지난 경우 품질을 0으로 설정 | ||
if (item.sellIn < QUALITY_MIN) { | ||
item.quality = QUALITY_MIN; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.gildedrose.update; | ||
|
||
import static com.gildedrose.update.ItemConstants.*; | ||
|
||
import com.gildedrose.Item; | ||
|
||
public class Conjured extends UpdateLogic { | ||
|
||
@Override | ||
public void update(Item item) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저의 품질 감소 로직보다 훨씬 더 가독성 좋고 간결하게 작성하신 거 같습니다! |
||
|
||
//"Conjured" 아이템은 일반 아이템의 2배의 속도로 품질(Quality)이 저하 | ||
decreaseQuality(item, QUALITY_DECREMENT_MULTIPLIER); | ||
decreaseSellIn(item); | ||
|
||
// 판매 기한이 0일 이하인 경우, 품질(Quality)을 추가로 2배 감소 | ||
if (item.sellIn < QUALITY_MIN && item.quality > QUALITY_MIN) { | ||
item.quality -= QUALITY_DECREMENT_MULTIPLIER; | ||
} | ||
|
||
if (item.quality < QUALITY_MIN) { | ||
item.quality = QUALITY_MIN; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.gildedrose.update; | ||
|
||
import static com.gildedrose.update.ItemConstants.*; | ||
|
||
import com.gildedrose.Item; | ||
|
||
public class DefaultItem extends UpdateLogic{ | ||
|
||
@Override | ||
public void update(Item item) { | ||
|
||
decreaseQuality(item, DEFAULT_QUALITY_DECREMENT); | ||
decreaseSellIn(item); | ||
|
||
if (item.sellIn < 0) { | ||
decreaseQuality(item, DEFAULT_QUALITY_DECREMENT); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.gildedrose.update; | ||
|
||
public class ItemConstants { | ||
public static final int QUALITY_MAX = 50; | ||
public static final int QUALITY_MIN = 0; | ||
public static final int DEFAULT_QUALITY_INCREMENT = 1; | ||
public static final int DEFAULT_QUALITY_DECREMENT = 1; | ||
public static final int QUALITY_DECREMENT_MULTIPLIER = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.gildedrose.update; | ||
|
||
import com.gildedrose.Item; | ||
|
||
public class Sulfuras extends UpdateLogic { | ||
@Override | ||
public void update(Item item) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.gildedrose.update; | ||
|
||
import static com.gildedrose.update.ItemConstants.*; | ||
|
||
import com.gildedrose.Item; | ||
|
||
public abstract class UpdateLogic { | ||
|
||
//판매일(SellIn) 감소 | ||
public void decreaseSellIn(Item item) { | ||
item.sellIn--; | ||
} | ||
|
||
//품질(Quality)를 지정한 increment만큼 증가 | ||
public void increaseQuality(Item item, int increment) { | ||
item.quality = Math.min(item.quality + increment, QUALITY_MAX); // QUALITY_MAX 이상으로 증가하지 않음 | ||
} | ||
|
||
//품질(Quality)를 지정한 decrement만큼 감소 | ||
public void decreaseQuality(Item item, int decrement) { | ||
item.quality = Math.max(item.quality - decrement, QUALITY_MIN); // QUALITY_MIN 이하로 감소하지 않음 | ||
} | ||
|
||
public abstract void update(Item item); | ||
} |
20 changes: 20 additions & 0 deletions
20
Java/src/main/java/com/gildedrose/update/UpdateLogicFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.gildedrose.update; | ||
|
||
import com.gildedrose.Item; | ||
|
||
public class UpdateLogicFactory { | ||
public static UpdateLogic getUpdateLogic(Item item){ | ||
switch (item.name) { | ||
case "Aged Brie": | ||
return new AgedBrie(); | ||
case "Backstage passes to a TAFKAL80ETC concert": | ||
return new BackstagePass(); | ||
case "Sulfuras, Hand of Ragnaros": | ||
return new Sulfuras(); | ||
case "Conjured Mana Cake": | ||
return new Conjured(); | ||
default: | ||
return new DefaultItem(); | ||
} | ||
} | ||
} | ||
Comment on lines
+3
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switch - case로 더 명확한 구조를 가지고 있네요! |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
기존 for문을 향상된 for문으로 수정하여 가독성이 좋아진 것 같네요👍