In this chapter, we have reviewed the various design alternatives of the __init__() method. The __init__() method is how objects are created, and it sets the initial state of an object.
We've looked at how all Python objects are subclasses of a common parent, the object class, and how the default __init__() method for the object class works. This consideration leads to two design strategies for placement of the __init__() method:
- We can define a common __init__() method for all subclasses of a hierarchy. This can lead to using a factory function, separate from the __init__() method, to help initialize objects correctly.
- We can push the __init__() method into each individual subclass of a complex hierarchy, and how this changes the design of classes.
After looking at building individual objects, we looked at how we can create composite objects. This involves a number...