New article by Larry Wall [perl.com]
One of the problems with OOP is that the terminology is intimidating. In the Visual Basic courses I teach, I like the use an analogy:
Library: Box of cookie cutters
Class: Cookie cutter
Object: Cookie
Memory: Cookie dough
Instantiate: Cut a cookie with the cutter
Object Variable: a single minded 3-year old; i.e. a cookie pointer..."look, daddy, a cookie", pointing at the cookie, and can only point at one cookie at a time.
Now that is Visual Basic terminology, but other languages have similar terms. This analogy holds up pretty well and helped me understand how it all works.
The thing that took a while form me to get, is that I started by treating the objects as somewhat sophisticated structs. But as time went on, I realized that any time you want to pull information from a property to do a calculation on it, should probably be turned into a method.
Another analogy that helped:
Object: Noun (specifically a direct object)
Property: Adjective
Method: Transitive Verb
For example:
Class: Book
Object: chris pointing at a specific Book
Property: cover is black
Property: title is Emphyrio
Property: author is Jack Vance
Method: Open
Method: Read(Page 12)
Method: Close
As in
Dim chris As Book
Set chris = New Book
chris.cover = vbBlack
chris.title = "Emphyrio"
chris.author = "Jack Vance"
Call chris.Open()
Call chris.Read(Page:=12)
Call chris.Close()
which would be valid VB syntax. The Read method basically is a command that tells VB "You read the book pointed at by my 3 year old named chris (and you'll want page 12)"
Or
If chris.Title = "Emphyrio" Then
Which asks if the book that chris is pointing has a title of Emphyrio.
Edited by: Xoc
Definitely. I've tried several times to get started on Java or the OOP side of Perl from several books, and can't understand the English used, never mind the code. Thanks, your analogies should help.
I really want to get into this as I like the concept (as I understand it) behind it all...