Created
March 21, 2025 17:43
-
-
Save trikitrok/086dc9895858acc081708f5ac7e3c9a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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