Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python abstract base classes, difference between mixin & abstract method

The following table shows varying abstract base classes that are used all over python. However, I am a bit confused exactly (in this context)

what is the difference between the Abstract Methods column and the Mixin Methods column. Is one optionally implemented and the other not?

I've been mulling it over and every one of my "theories" doesn't seem to be right.

reference


enter image description here

like image 237
AlanSTACK Avatar asked Mar 18 '16 20:03

AlanSTACK


People also ask

Is mixin an abstract class?

mR_fr0g, yes, BufferedRequestHandlerMixin is implemented as an abstract class. It's common to implement mixins using abstract classes in Java, as the abstract keyword notes that the class is designed for reuse and isn't mean to be used by itself (it also obviously prevents you from using it by itself).

What are Python mixin classes?

A mixin is a class that provides methods to other classes, but it's not considered a base class itself. 00:18 This special class is going to expose some methods that the derived class can utilize—methods that will essentially be mixed in to the derived class.

What is the difference between a mixin and inheritance?

Mixins are sometimes described as being "included" rather than "inherited". In short, the key difference from an inheritance is that mix-ins does NOT need to have a "is-a" relationship like in inheritance. From the implementation point of view, you can think it as an interface with implementations.

Is mixin same as interface?

A mixin is a class (interface, in WebAPI spec terms) in which some or all of its methods and/or properties are unimplemented, requiring that another class or interface provide the missing implementations.


1 Answers

Anything in the Abstract Methods column, you have to implement yourself. The ABC provides default implementations of the methods in the Mixin Methods column, implemented in terms of the methods you have to write.

like image 132
user2357112 supports Monica Avatar answered Oct 18 '22 03:10

user2357112 supports Monica