Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created March 21, 2025 17:46
Show Gist options
  • Save trikitrok/ff63dae0bb7e2cf48d7888a63182454c to your computer and use it in GitHub Desktop.
Save trikitrok/ff63dae0bb7e2cf48d7888a63182454c to your computer and use it in GitHub Desktop.
class RegisterSale {
// more code...
public addItem(code: Barcode): void {
//!! After Extract Method
const newItem = this.getInventory().getItemForBarCode(code);
this.items.push(newItem);
}
//!! Extracted method. Now we can apply Subclass & Override Method here!!
private getInventory(): Inventory {
// still using the Singleton!!
return Inventory.getInstance();
}
// more code...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment