Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created March 21, 2025 17:43
Show Gist options
  • Save trikitrok/086dc9895858acc081708f5ac7e3c9a5 to your computer and use it in GitHub Desktop.
Save trikitrok/086dc9895858acc081708f5ac7e3c9a5 to your computer and use it in GitHub Desktop.
class Inventory {
private static inventory: Inventory | null = null;
public static getInstance(): Inventory {
if (this.inventory === null) {
this.inventory = new Inventory();
}
return this.inventory;
}
public getItemForBarCode(code: Barcode): Item {
// get item with barcode from persistence
//...
}
}
class RegisterSale {
// more code...
public addItem(code: Barcode): void {
// using the Singleton!! x(
const newItem = Inventory.getInstance().getItemForBarCode(code);
this.items.push(newItem);
}
// more code...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment