mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +00:00
improve the if statement
improve the If statement to a switch
This commit is contained in:
parent
e04bd79518
commit
b05de45437
@ -57,8 +57,8 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>8</source>
|
<source>18</source>
|
||||||
<target>8</target>
|
<target>18</target>
|
||||||
<compilerArgs>--enable-preview</compilerArgs>
|
<compilerArgs>--enable-preview</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@ -4,19 +4,18 @@ public class StorageItem {
|
|||||||
protected Item item;
|
protected Item item;
|
||||||
|
|
||||||
public static StorageItem createItem(Item item) {
|
public static StorageItem createItem(Item item) {
|
||||||
if (item.name.equals(AgeddBrie.NAME)) {
|
switch (item.name) {
|
||||||
return new AgeddBrie(item);
|
case AgeddBrie.NAME:
|
||||||
|
return new AgeddBrie(item);
|
||||||
|
case BackstagePasses.NAME:
|
||||||
|
return new BackstagePasses(item);
|
||||||
|
case Sulfuras.NAME:
|
||||||
|
return new Sulfuras(item);
|
||||||
|
case Conjured.NAME:
|
||||||
|
return new Conjured(item);
|
||||||
|
case default:
|
||||||
|
return new StorageItem(item);
|
||||||
}
|
}
|
||||||
if (item.name.equals(BackstagePasses.NAME)) {
|
|
||||||
return new BackstagePasses(item);
|
|
||||||
}
|
|
||||||
if (item.name.equals(Sulfuras.NAME)) {
|
|
||||||
return new Sulfuras(item);
|
|
||||||
}
|
|
||||||
if (item.name.equals(Conjured.NAME)) {
|
|
||||||
return new Conjured(item);
|
|
||||||
}
|
|
||||||
return new StorageItem(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItem(Item item) {
|
public StorageItem(Item item) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user