Chapter 8. Object Orientation: The Next Few Steps
No ties bind so strongly as the links of inheritance.
This chapter is essentially a motley collection of ideas, techniques, and opinions related to Perl objects. I have not attempted to weave these threads too closely. The topics are as follows:
- Efficient attribute storage
Search for an alternative way of representing object attributes, instead of hash tables. The two strategies examined in this chapter occupy less space and are faster.
How to use
AUTOLOADto automatically forward method calls.
- Inheritance and composition
What I find objectionable about inheritance, along with alternative ways of structuring classes.
Efficient Attribute Storage
Hash tables have traditionally been used for storing object attributes. There are good reasons for doing this:
Each attribute is self-describing (that is, the name and type of each attribute are easily obtained from the object), which makes it easy to write readable code. It also helps modules that do automatic object persistence or visualization of objects, without the object’s explicit cooperation.
Each class in an inheritance hierarchy can add attributes freely and independently.
In fact, each instance (not just the class) can possess a unique set of attributes and can change this set at run time. The artificial intelligence community often uses this slot- or frame-based approach because it adapts itself very well to new pieces of information.
Of course, not every problem ...