-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype_example.dart
57 lines (47 loc) · 1.63 KB
/
prototype_example.dart
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Interface Prototype que define o método de clonagem
abstract class Prototype {
Prototype clone();
}
// Implementação concreta do relatório de vendas
class SalesReport implements Prototype {
// Lista para armazenar datas de vendas
final List<String> _salesDates = [];
@override
Prototype clone() {
// Retorna uma nova instância de SalesReport
return SalesReport();
}
}
// Implementação concreta do relatório de inventário
class InventoryReport implements Prototype {
// Lista para armazenar produtos
final List<String> _products = [];
@override
Prototype clone() {
// Retorna uma nova instância de InventoryReport
return InventoryReport();
}
}
// Classe para gerenciar protótipos de relatórios
class ReportManager {
// Mapa para armazenar os protótipos de relatórios registrados
Map<String, Prototype> _reportPrototypes = {};
// Método para registrar um protótipo de relatório
void register(String name, Prototype prototype) {
_reportPrototypes[name] = prototype;
}
// Método para obter um protótipo clonado com base no nome registrado
Prototype? getPrototype(String name) {
return _reportPrototypes[name]?.clone();
}
}
void main() {
// Criação do gerenciador de relatórios
var reportManager = ReportManager();
// Registro dos protótipos de relatórios
reportManager.register("SalesReport", SalesReport());
reportManager.register("InventoryReport", InventoryReport());
// Obtenção de clones dos protótipos registrados
var salesReport = reportManager.getPrototype("SalesReport");
var inventoryReport = reportManager.getPrototype("InventoryReport");
}