Brief Refresher on Object-Oriented Lingo
An object is a data structure with a collection of behaviors. We generally speak of the behaviors as acted out by the object directly, sometimes to the point of anthropomorphizing the object. For example, we might say that a rectangle “knows” how to display itself on the screen, or that it “knows” how to compute its own area.
Every object gets its behaviors by virtue of being an instance of a class. The class defines methods: behaviors that apply to the class and its instances. When the distinction matters, we refer to methods that apply only to a particular object as instance methods, and those that apply to the entire class as class methods. But this is only a convention—to Perl, a method is just a method, distinguished only by the type of its first argument.
You can think of an instance method as some action performed by a particular object, such as printing itself out, copying itself, or altering one or more of its properties (“set this sword’s name to Andúril”). Class methods might perform operations on many objects collectively (“display all swords”) or provide other operations that aren’t dependent on any particular object (“from now on, whenever a new sword is forged, register its owner in this database”). Methods that generate instances (objects) of a class are called constructor methods (“create a sword with a gem-studded hilt and a secret inscription”). These are usually class methods (“make me a new sword”) but can also be instance ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access