Move logic that maps item names to Update behavior to a new resolver file

This commit is contained in:
Arno Chauveau 2025-07-24 11:49:33 +02:00
parent f35d2e9c84
commit 1563d86e90
3 changed files with 13 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import { Item } from "@app/item";
import { IUpdateBehavior, LegacyBehavior } from "@app/update-behaviors";
import { getUpdateBehaviorFor } from "@app/update-behaviors";
export class GildedRose {
// also can't edit this because of the kata rules.
@ -12,14 +12,7 @@ export class GildedRose {
updateQuality() {
return this.items.map((item) => {
return this.#getUpdateBehaviorFor(item).update();
return getUpdateBehaviorFor(item).update();
});
}
#getUpdateBehaviorFor(item: Item): IUpdateBehavior {
switch (item.name) {
default:
return new LegacyBehavior(item);
}
}
}

View File

@ -0,0 +1,10 @@
import { Item } from "@app/item";
import { IUpdateBehavior } from "./update-behavior.interface";
import { LegacyBehavior } from "./legacy-behavior";
export function getUpdateBehaviorFor(item: Item): IUpdateBehavior {
switch (item.name) {
default:
return new LegacyBehavior(item);
}
}

View File

@ -1,2 +1,2 @@
export * from "./update-behavior.interface";
export * from "./legacy-behavior";
export * from "./behavior-resolver";