-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.ts
More file actions
32 lines (26 loc) · 793 Bytes
/
Copy pathmodels.ts
File metadata and controls
32 lines (26 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Product {
id: number;
name: string;
price: number;
// Constructor para inicializar los atributos
constructor(id: number, name: string, price: number) {
this.id = id;
this.name = name;
this.price = price;
}
}
class ProductCollection {
private products: Product[] = []; // Array para almacenar productos
getAll(): Product[] {
// Implementación para recuperar todos los productos
return this.products;
}
getById(id: number): Product | null {
// Implementación para recuperar un producto por su ID
return this.products.find(product => product.id === id) || null;
}
add (product: Product): void {
this.products.push(product);
}
}
export { Product, ProductCollection };