已读71%
预计阅读本页时间:-
预计阅读本页时间:-
Test Your Knowledge: Answers
- Multiple inheritance occurs when a class inherits from more than one superclass; it’s useful for mixing together multiple packages of class-based code. The left-to-right order in class statement headers determines the order of attribute searches.
- Delegation involves wrapping an object in a proxy class, which adds extra behavior and passes other operations to the wrapped object. The proxy retains the interface of the wrapped object.
- Composition is a technique whereby a controller class embeds and directs a number of objects, and provides an interface all its own; it’s a way to build up larger structures with classes.
- Bound methods combine an instance and a method function; you can call them without passing in an instance object explicitly because the original instance is still available.
- Pseudoprivate attributes (whose names begin with two leading underscores: __X) are used to localize names to the enclosing class. This includes both class attributes like methods defined inside the class, and self instance attributes assigned inside the class. Such names are expanded to include the class name, which makes them unique.