Question from the Java and Craftsmanship test

Improve the maintainability of this code by using polymorphism for items.

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 219 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!