Skip to content

Commit 842f076

Browse files
committed
26-c#-SOLID-SRP
1 parent 753bf90 commit 842f076

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

Roadmap/26 - SOLID SRP/c#/kenysdev.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#pragma warning disable CA1050 //namespace
2+
/*
3+
╔══════════════════════════════════════╗
4+
║ Autor: Kenys Alvarado ║
5+
║ GitHub: https://github.com/Kenysdev ║
6+
║ 2024 - C# ║
7+
╚══════════════════════════════════════╝
8+
-------------------------------------------------
9+
* SOLID: PRINCIPIO DE RESPONSABILIDAD ÚNICA (SRP)
10+
-------------------------------------------------
11+
# Se centra en la claridad, la cohesión y la separación de intereses.
12+
# Cada clase debe tener una única razón para cambiar.
13+
# Los metodos de una clase deben estar estrechamente relacionadas.
14+
15+
__________________________________
16+
* EJERCICIO:
17+
* Explora el "Principio SOLID de Responsabilidad Única (Single Responsibility
18+
* Principle, SRP)" y crea un ejemplo simple donde se muestre su funcionamiento
19+
* de forma correcta e incorrecta.
20+
*/
21+
22+
// # SIN APLICAR EL PRINCIPIO:
23+
using System.Collections.Generic;
24+
25+
public class NoSRP {
26+
private readonly List<string> customers;
27+
private readonly List<string> suppliers;
28+
29+
public NoSRP() {
30+
customers = [];
31+
suppliers = [];
32+
}
33+
34+
public void AddCustomer(string name) {
35+
customers.Add(name);
36+
}
37+
38+
public void AddSupplier(string name) {
39+
suppliers.Add(name);
40+
}
41+
42+
public void RemoveCustomer(string name) {
43+
customers.Remove(name);
44+
}
45+
46+
public void RemoveSupplier(string name) {
47+
suppliers.Remove(name);
48+
}
49+
}
50+
51+
// _______________________________________
52+
// APLICANDO EL PRINCIPIO:
53+
54+
public class Customers {
55+
private readonly List<string> customers;
56+
57+
public Customers() {
58+
customers = [];
59+
}
60+
61+
public void Add(string name) {
62+
customers.Add(name);
63+
}
64+
65+
public void Remove(string name) {
66+
customers.Remove(name);
67+
}
68+
}
69+
70+
public class Suppliers {
71+
private readonly List<string> suppliers;
72+
73+
public Suppliers() {
74+
suppliers = [];
75+
}
76+
77+
public void Add(string name) {
78+
suppliers.Add(name);
79+
}
80+
81+
public void Remove(string name) {
82+
suppliers.Remove(name);
83+
}
84+
}

0 commit comments

Comments
 (0)