Medium
This code works and the client needs are met, it can however be largely improved.
I which way could it be improved, regarding the maintenability ?
class GildedRose {
  private static final String SULFURAS_NAME = "Sulfuras, Hand of Ragnaros";
  private static final String BACKSTAGE_PASSES_NAME = "Backstage passes to a TAFKAL80ETC concert";
  private static final String AGED_BRIE_NAME = "Aged Brie";
  Item[] items;
  public GildedRose(Item[] items) {
    this.items = items;
  }
  public void updateQuality() {
    for (Item item : items) {
      if (SULFURAS_NAME.equals(item.name)) {
        continue;
      }
      item.sellIn = item.sellIn - 1;
      if (AGED_BRIE_NAME.equals(item.name)) {
        updateAgedBrie(item);
      } else if (BACKSTAGE_PASSES_NAME.equals(item.name)) {
        updateBackstagePass(item);
      } else {
        updateNormalItem(item);
      }
    }
  }
  private void updateAgedBrie(Item item) {
    increaseQuality(item);
    if (item.sellIn < 0) {
      increaseQuality(item);
    }
  }
  private void updateBackstagePass(Item item) {
    increaseQuality(item);
    if (item.sellIn < 10) {
      increaseQuality(item);
    }
    if (item.sellIn < 5) {
      increaseQuality(item);
    }
    if (item.sellIn < 0) {
      item.quality = 0;
    }
  }
  private void updateNormalItem(Item item) {
    decreaseQuality(item);
    if (item.sellIn < 0) {
      decreaseQuality(item);
    }
  }
  private void increaseQuality(Item item) {
    if (item.quality < 50) {
      item.quality = item.quality + 1;
    }
  }
  private void decreaseQuality(Item item) {
    if (item.quality > 0) {
      item.quality = item.quality - 1;
    }
  }
}
Author: Clément DevosStatus: PublishedQuestion passed 433 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!
4
Write a function that returns the first character of a string in Java4
This code allows to randomly get numbers between 1 to 31 in results. Should have declard SimpleDateFormat in the Thread.1
Which Java 7 feature was only usable in Java 8?1
Write a Java implementation of the FizzBuzz code kata.1
Java code that replaces keys in a template with their values.1
What does SRP stand for?1
A Java class that converts Arabic numbers to Roman numerals.