Herencia multinivel

Principios de ingeniería de software en Python

Adam Spannbauer

Machine Learning Engineer at Eastman

Creando una clase Tweet

  Archivo de clase Tweet

Principios de ingeniería de software en Python

Herencia multinivel

Árbol genealógico de herencia

Principios de ingeniería de software en Python

Herencia multinivel

Árbol genealógico de herencia multinivel

Principios de ingeniería de software en Python

Herencia múltiple

Árbol genealógico de herencia múltiple

Principios de ingeniería de software en Python

Herencia multinivel y super

class Parent:
    def __init__(self):
        print("¡Soy un padre!")


class Child(Parent):
    def __init__(self):
        Parent.__init__()
        print("¡Soy un hijo!")

class SuperChild(Child): def __init__(self): super().__init__() print("¡Soy un superhijo!")

Aprende más sobre herencia múltiple y super().

Principios de ingeniería de software en Python

Herencia multinivel y super

class Parent:
    def __init__(self):
        print("¡Soy un padre!")

class SuperChild(Parent):
    def __init__(self):
        super().__init__()
        print("¡Soy un superhijo!")

class Grandchild(SuperChild): def __init__(self): super().__init__() print("¡Soy un nieto!")
grandchild = Grandchild()
¡Soy un padre!
¡Soy un superhijo!
¡Soy un nieto!
Principios de ingeniería de software en Python

Seguimiento de atributos heredados

# Crear una instancia de SocialMedia
sm = SocialMedia('@DataCamp #DataScience #Python #sklearn')

# ¿Qué métodos tiene sm? ¯\_(ツ)_/¯ dir(sm)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', 
'__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', 
'__str__', '__subclasshook__', '__weakref__', '_count_hashtags', 
'_count_mentions', '_count_words', '_tokenize', 'hashtag_counts', 
'mention_counts', 'text', 'tokens', 'word_counts']
Principios de ingeniería de software en Python

¡Vamos a practicar!

Principios de ingeniería de software en Python

Preparing Video For Download...