Multiple inheritance 00:00:00 Make a prediction You will walk a method through the actual resolution order and detect duplicated work when several parents participate. A request-handling mixin calls the next server handler, but the combined class also calls the base handler directly. How many times might the request run? Twice. Follow the resolution chain before invoking a particular parent by name. An implementation that already delegates can cause duplicate work when another route calls the same base again. 00:00:31 Noor and the swimming bus A bus can travel on a road and cross a short stretch of water. If each propulsion manual begins by starting the same engine, following both complete manuals may start it twice. Independent capabilities can be useful, but inherited implementations must agree on how common work is reached. Trace the full call route rather than counting how many parent names appear. Multiple inheritance means that a class names more than one direct parent class: class WorkingStudent(Student, Employee). An object of it is a student and an employee at once, and it has the methods and fields of both. Some things really have several independent sides. A threaded web server is a web server and is threaded. A product can be saved, has a price and has a label. One tree cannot show independent sides without copies. 00:01:25 Combine independent server roles A server already knows how to accept and handle a request. A threading mixin can arrange for handling to run on another thread. The combined class must place the mixin where the method resolution order actually finds its hook. The mixin then delegates the remaining work. Trace one request and count exactly one handler invocation. This catches duplicate work from calling two parent implementations manually. Send request forty-two through both mixins and make each record when it enters. Confirm that the shared handler runs once. If one mixin calls the base directly, another behaviour can vanish; if two parents both call it directly, the request might actually run twice. 00:02:10 Use composition when parents clash A camera and a printer both expose reset but control different devices. Inheriting both creates an ambiguous instruction. A workstation that owns one camera and one printer can expose separate reset camera and reset printer actions with clear ownership. Give both parent devices a method called start, but have one start the motor and the other start sampling. A single inherited name cannot communicate which side effect the caller wanted. Two explicit collaborators let the object invoke each action in a documented order. Cooperative super calls still fail when one parent does not delegate or expects an incompatible argument list. If independent parent implementations fight over state or method meaning, composition lets the caller choose a named collaborator instead. Python socketserver. class ThreadingUDPServer(ThreadingMixIn, UDPServer). The documentation explains that the mix-in comes first because it overrides a method of the server. Python http.server. ThreadingHTTPServer is HTTPServer with threads, made with the same mix-in. The second use is what makes a mix-in worth having. 00:03:29 Try an interview follow-up How would you test a class with four mixins? I first attach each mixin to a tiny recording base so that I can see every delegated call. For the combined class, I assert the resolution order, verify that each required initializer ran once, and exercise a result that changes if two mixins are reversed. Independent tests alone miss those interactions. Imagine two reusable parents that both initialize a logging sink. Construct a class that uses both. Trace the initialization order in the language you chose and count how many sinks open. If composing a logger and a clock makes each dependency explicit, explain why that version is easier to initialize and test. 00:04:16 What to take with you Many types are harmless, many behaviours need an order, many states need a plan. Ask which of the three you are about to inherit. Parents that cooperate take keyword arguments, keep what is theirs, pass the rest on and always call super. One parent that does not call it cuts the line.