Intenta interpretar el código de forma correcta previamente a aplicarlo a tu trabajo si ttienes algo que aportar puedes compartirlo con nosotros.
Ejemplo 1: qué es la composición en python
# It's when a class has a (is made-of) another class.# ExampleclassThing(object):deffunc(self):print("Function ran from class Thing().")classOtherThing(object):# Note that I don't use inheritance to get the func() functiondef__init__(self):
self.thing = Thing()# Setting the composition, see how this class has-a another class in it?deffunc(self):
self.thing.func()# Just runs the function in class Thing()defotherfunc(self):print("Function ran from class OtherThing().")
random_object = OtherThing()
random_object.func()# Still works, even though it didn't inherit from class Thing()
random_object.otherfunc()
Ejemplo 2: composición en python
In composition one of the classes is composed of one or more instance of other classes. In other words one classis container and other classis content andif you delete the container object then all of its contents objects are also deleted
Ejemplo 3: composición de funciones en python
defcompose2(f, g):returnlambda x: f(g(x))
Ejemplo 4: composición en python
In composition one of the classes is composed of one or more instance of other classes. In other words one classis container and other classis content andif you delete the container object then all of its contents objects are also deleted
Eres capaz de corroborar nuestra faena ejecutando un comentario o dejando una puntuación te damos la bienvenida.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)