上QQ阅读APP看书,第一时间看更新
Multi-strategy __init__()
We may have objects that are created from a variety of sources. For example, we might need to clone an object as part of creating a memento, or freeze an object so that it can be used as the key of a dictionary or placed into a set; this is the idea behind the set
and frozenset
built-in classes.
There are several overall design patterns that have multiple ways to build an object. One design pattern is complex __init__()
that is called multi-strategy initialization. Also, there are multiple class-level (static) constructor methods.
These are incompatible approaches. They have radically different interfaces.