Skip to content

Commit 305bf2d

Browse files
committed
mouredev#29 - Python
1 parent d2de78e commit 305bf2d

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# /*
2+
# * EJERCICIO:
3+
# * Explora el "Principio SOLID de Segregación de Interfaces (Interface Segregation Principle, ISP)"
4+
# * y crea un ejemplo simple donde se muestre su funcionamiento de forma correcta e incorrecta.
5+
# *
6+
7+
8+
9+
# Viola el principio de segregacion ..
10+
from abc import ABC,abstractmethod
11+
12+
class Worker(ABC):
13+
@abstractmethod
14+
def sleep(self):
15+
pass
16+
17+
@abstractmethod
18+
def work(self):
19+
pass
20+
21+
@abstractmethod
22+
def eat(self):
23+
pass
24+
25+
class Robot(Worker):
26+
def work(self):
27+
print("Robot is working...")
28+
29+
def sleep(self):
30+
pass
31+
32+
def eat(self):
33+
pass
34+
35+
class Human (Worker):
36+
def sleep(self):
37+
print("Human is sleeping...")
38+
def work(self):
39+
print("Human is working...")
40+
def eat(self):
41+
print("Human is eating..")
42+
43+
print("Whitout iSP")
44+
R = Robot()
45+
R.work()
46+
H = Human()
47+
H.work()
48+
H.eat()
49+
H.sleep()
50+
51+
# aplicando principio de segregacion
52+
53+
class WorkInterface(ABC):
54+
@abstractmethod
55+
def work(self):
56+
pass
57+
58+
class EatINterface(ABC):
59+
@abstractmethod
60+
def eat(self):
61+
pass
62+
63+
class SleepInterface(ABC):
64+
@abstractmethod
65+
def sleep(self):
66+
pass
67+
68+
class Human(WorkInterface,SleepInterface,EatINterface):
69+
70+
def work(self):
71+
print("HUman is working...")
72+
73+
def sleep(self):
74+
print("HUman is sleeping")
75+
76+
def eat(self):
77+
print("Human is eating")
78+
79+
class Robot(WorkInterface):
80+
def work(self):
81+
print("Robot is workiing...")
82+
83+
84+
print("ISP")
85+
Ro = Robot()
86+
Ro.work()
87+
Hu = Human()
88+
Hu.sleep()
89+
Hu.work()
90+
Hu.eat()
91+
92+
93+
# EXTRA
94+
95+
# * DIFICULTAD EXTRA (opcional):
96+
# * Crea un gestor de impresoras.
97+
# * Requisitos:
98+
# * 1. Algunas impresoras sólo imprimen en blanco y negro.
99+
# * 2. Otras sólo a color.
100+
# * 3. Otras son multifunción, pueden imprimir, escanear y enviar fax.
101+
# * Instrucciones:
102+
# * 1. Implementa el sistema, con los diferentes tipos de impresoras y funciones.
103+
# * 2. Aplica el ISP a la implementación.
104+
# * 3. Desarrolla un código que compruebe que se cumple el principio.
105+
# */
106+
107+
108+
class Scaninterface(ABC):
109+
@abstractmethod
110+
def Scan(self):
111+
pass
112+
113+
class FAXinterface(ABC):
114+
@abstractmethod
115+
def Fax(self):
116+
pass
117+
118+
class PrintetInterface(ABC):
119+
@abstractmethod
120+
def Print(self):
121+
pass
122+
123+
124+
class ColorPrintInterface(ABC):
125+
@abstractmethod
126+
def Print_color(self):
127+
pass
128+
129+
class Printer (PrintetInterface):
130+
def Print(self):
131+
print("IMpresora solo imprime white and black")
132+
133+
134+
class PrinterColor(ColorPrintInterface):
135+
def Print_color(self):
136+
print("Impresora a Color...")
137+
138+
class MultiFunction(PrintetInterface,ColorPrintInterface,Scaninterface,FAXinterface):
139+
def Print(self):
140+
print("Multifuncion Printing white and Black...")
141+
142+
def Print_color(self):
143+
print("Multifuncion Printing in color...")
144+
145+
146+
def Scan(self):
147+
print("Mutifunction Scanning...")
148+
149+
def Fax(self):
150+
print("MultiFunction Faxing...")
151+
print("PRINTER")
152+
153+
printer_wb = Printer()
154+
printer_wb.Print()
155+
printer_c = PrinterColor()
156+
printer_c.Print_color()
157+
158+
multi = MultiFunction()
159+
multi.Print()
160+
multi.Print_color()
161+
multi.Scan()
162+
multi.Fax()

0 commit comments

Comments
 (0)