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
710import matplotlib .pyplot as plt
811import 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
5561logging .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 " )
133141my_library = Library ()
134142my_library .add_user ("Alice" , 1 , "alice@dev" )
135143my_library .add_user ("Bob" , 2 , "bob@dev" )
@@ -152,6 +160,16 @@ def return_book(self, title: str, name: str):
152160my_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+
155173class 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
255274my_library_v2 = Library_v2 ()
256275my_library_v2 .add_user ("Alice" , 1 , "alice@dev" )
0 commit comments