mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-08 11:11:24 +00:00
Move logic that maps item names to Update behavior to a new resolver file
This commit is contained in:
parent
f35d2e9c84
commit
1563d86e90
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
TypeScript/app/update-behaviors/behavior-resolver.ts
Normal file
10
TypeScript/app/update-behaviors/behavior-resolver.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
@ -1,2 +1,2 @@
|
||||
export * from "./update-behavior.interface";
|
||||
export * from "./legacy-behavior";
|
||||
export * from "./behavior-resolver";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user