Python 3 Deep Dive Part 4 Oop High Quality Guide

class Movable: def move(self): pass class Flyable: def fly(self): pass

from collections.abc import Sized class MyContainer: def (self): return 10 python 3 deep dive part 4 oop high quality

: Register virtual subclasses.

Follow for more Python 3 deep dives.

: Do not overuse __ (double underscore). It breaks subclassing. Use _ for internal attributes and trust other developers. Python is a "consenting adults" language. 5. Inheritance Done Right: Composition over Inheritance Inheritance is overused. The Gang of Four principle: Favor object composition over class inheritance . class Movable: def move(self): pass class Flyable: def

from abc import ABC, abstractmethod class Stream(ABC): @abstractmethod def read(self): pass data): print(f"writing {data}")

@abstractmethod def write(self, data): pass class FileStream(Stream): def read(self): return "data" def write(self, data): print(f"writing {data}")