Properties: Getters and Setters Done the Python Way
@property turns a method into an attribute. It lets you start with a plain attribute and add validation later without changing a single line of callin...
Properties, class and static methods, abstract base classes, the MRO, composition and mixins.
5 notes
@property turns a method into an attribute. It lets you start with a plain attribute and add validation later without changing a single line of callin...
An instance method receives the object, a class method receives the class, and a static method receives neither. Each exists for a different job.
An abstract base class states what subclasses must implement, and refuses to let an incomplete one be created. It is how Python enforces a contract.
A class can inherit from several parents. The method resolution order decides which version wins, and C3 linearisation is the algorithm that computes...
Inheritance says "is a"; composition says "has a". Most of the time the honest answer is "has a", and the resulting design is easier to change.