MIXINS in Python explained with an example

Поделиться
HTML-код
  • Опубликовано: 7 дек 2024
  • In this video you see an mix-in example Python. You learn what problems a mixin can solve and how multiple inheritance is used to achieve mixins in Python.
    C H A P T E R S
    0:09 Single inheritance
    0:50 Adding behavior requires inheritance to prevent duplicate code
    1:26 Inheritance violates single responsibility principle
    2:05 Small addition affects whole system
    2:20 Options to implement serialization functionality
    2:35 Introduce mixin class
    3:30 Use multiple inheritance to achieve mixins in Python
    3:48 Difference between mixins and multiple inheritance
    M Y O N L I N E T R A I N I N G
    🎓Like my style of teaching? Try free chapters of my online courses: pythonforevery...
    #pythonforeveryone #programming #python

Комментарии • 12

  • @Raisincookies55
    @Raisincookies55 Месяц назад

    short and to the point. great work

  • @EmadRahman_eee
    @EmadRahman_eee Год назад +1

    Thank you very much for the video.

  • @bomthanhha
    @bomthanhha Год назад +1

    I think dependency injection to achieve the same thing without using inheritance. For example, I can assign self.serializer = Serializer() at def __init__(). Am I thinking correctly? When should I decide to use dependency injection vs mixins and vice versa?

    • @python-for-everyone
      @python-for-everyone  Год назад

      Dependency injection is the technique to inject objects into other objects. Could it be you mean when to favor composition over inheritance? In this video, I show a scenario where DI and composition work very well: ruclips.net/video/BdMO1IR-800/видео.html

  • @Иван-д6ф6с
    @Иван-д6ф6с Год назад

    Great!

  • @TomasHayes
    @TomasHayes 11 месяцев назад

    I'm struggling with IDE typing errors when a mixin access to properties it doesn't posses (yet).
    Any advice on how to handle that properly? Thank you!

    • @python-for-everyone
      @python-for-everyone  11 месяцев назад

      Yep, that is a problem of dynamically typed languages. There is no guarantee that attributes will be present. If you want to satisfy the type checker, you could use base classes or protocols.

  • @Иван-д6ф6с
    @Иван-д6ф6с Год назад

    Can you make video abou SOLID principles?

    • @python-for-everyone
      @python-for-everyone  Год назад

      Here is a youtube video: ruclips.net/video/VqeBgD5TuAQ/видео.html on the Open Closed Principle and if you want to support me, you can enroll in my S.O.L.I.D. course on Udemy: pythonforeveryone.com/python-solid-online-training.html

  • @rajdeepjadav6263
    @rajdeepjadav6263 2 дня назад

    Allways use dark mode and big fonts.