-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonFactory.cs
More file actions
26 lines (22 loc) · 1.07 KB
/
PersonFactory.cs
File metadata and controls
26 lines (22 loc) · 1.07 KB
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
namespace Health;
// Factory para criar instâncias de Person ou Athlete, agora implementando a interface
public class PersonFactory : IPersonFactory
{
private readonly IHealthRules _rules;
// Construtor recebe IHealthRules injetado pelo contêiner
public PersonFactory(IHealthRules rules)
{
_rules = rules;
}
// Implementa o método da interface para criar instâncias
public Person Create(bool isAthlete, double weight, double height)
{
return isAthlete ? new Athlete(_rules, weight, height) : new Person(_rules, weight, height);
}
// Comentário: Implementa IPersonFactory, usando IHealthRules injetado para criar
// instâncias. Agora, outras classes podem depender de IPersonFactory em vez de
// PersonFactory diretamente.
// SOLID - S (Single Responsibility): Responsável apenas por criar instâncias de Person.
// SOLID - O (Open/Closed): Pode ser estendido com novas implementações da interface.
// SOLID - D (Dependency Inversion): Depende da abstração IHealthRules e é abstraído por IPersonFactory.
}