Skip to content

Commit 8a6ea8a

Browse files
committed
Se agregan comentarios para generar secciones o capitulos en el código
1 parent b6e22b2 commit 8a6ea8a

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

Roadmap/26 - SOLID SRP/python/LuisOlivaresJ.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# ---------------------------------------------
12
# Ejemplo de Principio de responsabilidad única
2-
# """
3+
# ---------------------------------------------
34

45
# El siguiente ejemplo muestra un código que viola el principio de responsabilidad única.
5-
# La clase ImageManager tiene dos responsabilidades: obtener estadísticas de una imagen y graficarla.
6+
# La clase ImageManager tiene dos responsabilidades:
7+
# 1.- Obtener estadísticas de una imagen
8+
# 2.- Graficar una imagen
69

710
import matplotlib.pyplot as plt
811
import numpy as np
@@ -47,10 +50,13 @@ def plot(self):
4750
plt.show()
4851

4952

50-
51-
53+
# ---------------------------------------------
5254
# Dificultad extra
5355
# Sistema de gestion para una bibioteca
56+
#
57+
# FORMA INCORRECTA
58+
#
59+
# ---------------------------------------------
5460

5561
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s")
5662

@@ -130,6 +136,8 @@ def return_book(self, title: str, name: str):
130136

131137

132138
# Testing the class
139+
print("\n"*3)
140+
print("### Testing: Dificultad extra (FORMA INCORRECTA)\n")
133141
my_library = Library()
134142
my_library.add_user("Alice", 1, "alice@dev")
135143
my_library.add_user("Bob", 2, "bob@dev")
@@ -152,6 +160,16 @@ def return_book(self, title: str, name: str):
152160
my_library.print_users()
153161

154162

163+
# ---------------------------------------------
164+
# Dificultad extra
165+
# Sistema de gestion para una bibioteca
166+
#
167+
# Forma CORRECTA
168+
#
169+
# Se crean dos clases diferentes, BooksManager y UsersManager, para manejar los libros y a los usuarios.
170+
# Se crea una clase que maneja la biblioteca y delega las responsabilidades a las clases BooksManeger y UsersManager.
171+
# ---------------------------------------------
172+
155173
class BooksManeger:
156174
def __init__(self):
157175
self.books = []
@@ -248,9 +266,10 @@ def return_book(self, title: str, name: str):
248266
self.books_m.return_book(title)
249267
self.users_m.return_book(title, name)
250268

251-
print("\n"*3)
252-
print("### Testing: Dificultad extra\n")
269+
253270
# Testing the classes
271+
print("\n"*3)
272+
print("### Testing: Dificultad extra (FORMA CORRECTA)\n")
254273

255274
my_library_v2 = Library_v2()
256275
my_library_v2.add_user("Alice", 1, "alice@dev")

0 commit comments

Comments
 (0)