forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mouredev#4602 from Kenysdev/26.cs
#26 - c#
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma warning disable CA1050 //namespace | ||
/* | ||
╔══════════════════════════════════════╗ | ||
║ Autor: Kenys Alvarado ║ | ||
║ GitHub: https://github.com/Kenysdev ║ | ||
║ 2024 - C# ║ | ||
╚══════════════════════════════════════╝ | ||
------------------------------------------------- | ||
* SOLID: PRINCIPIO DE RESPONSABILIDAD ÚNICA (SRP) | ||
------------------------------------------------- | ||
# Se centra en la claridad, la cohesión y la separación de intereses. | ||
# Cada clase debe tener una única razón para cambiar. | ||
# Los metodos de una clase deben estar estrechamente relacionadas. | ||
__________________________________ | ||
* EJERCICIO: | ||
* Explora el "Principio SOLID de Responsabilidad Única (Single Responsibility | ||
* Principle, SRP)" y crea un ejemplo simple donde se muestre su funcionamiento | ||
* de forma correcta e incorrecta. | ||
*/ | ||
|
||
// # SIN APLICAR EL PRINCIPIO: | ||
using System.Collections.Generic; | ||
|
||
public class NoSRP { | ||
private readonly List<string> customers; | ||
private readonly List<string> suppliers; | ||
|
||
public NoSRP() { | ||
customers = []; | ||
suppliers = []; | ||
} | ||
|
||
public void AddCustomer(string name) { | ||
customers.Add(name); | ||
} | ||
|
||
public void AddSupplier(string name) { | ||
suppliers.Add(name); | ||
} | ||
|
||
public void RemoveCustomer(string name) { | ||
customers.Remove(name); | ||
} | ||
|
||
public void RemoveSupplier(string name) { | ||
suppliers.Remove(name); | ||
} | ||
} | ||
|
||
// _______________________________________ | ||
// APLICANDO EL PRINCIPIO: | ||
|
||
public class Customers { | ||
private readonly List<string> customers; | ||
|
||
public Customers() { | ||
customers = []; | ||
} | ||
|
||
public void Add(string name) { | ||
customers.Add(name); | ||
} | ||
|
||
public void Remove(string name) { | ||
customers.Remove(name); | ||
} | ||
} | ||
|
||
public class Suppliers { | ||
private readonly List<string> suppliers; | ||
|
||
public Suppliers() { | ||
suppliers = []; | ||
} | ||
|
||
public void Add(string name) { | ||
suppliers.Add(name); | ||
} | ||
|
||
public void Remove(string name) { | ||
suppliers.Remove(name); | ||
} | ||
} |