MIXINS in Python explained with an example

preview_player
Показать описание
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

#pythonforeveryone #programming #python
Рекомендации по теме
Комментарии
Автор

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?

bomthanhha
Автор

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!

TomasHayes
Автор

Can you make video abou SOLID principles?

bbbbbsssssfffff
Автор

cant we just write a serializer function (not a method in a class) and use it? why do we need to make it to a class in the first place?

akashgeorge