Imagine for a moment that you're writing the billing component of an online store. Now, there are several ways a customer can pay: they can use a credit card, a debit card, a check, etc. You could use a switch statement (or an if/elsif chain in Perl 5) to do it:
But maybe there are several steps involved--early in the process you have to authorize, then later you have to execute the transaction, and perhaps you need to store the info in a database so crackers can steal it. That requires three switch statements in different areas of the code. And then six months down the road, you want to add PayPal support, so you have to change three different switch statements, but in one of them you accidentally put 'payapl', but it's already gone into production so the company loses five thousand dollars and fires you.
You don't want to get fired.
So instead, you write an object to represent a payment method, and a subclass for each specific way of paying:
Now you can create the appropriate object exactly once:
And then later on, when it's time to authorize, all you need to do is put the statement $payobj.authorize()--no nasty switch required.
In essence, an object is a way to make tasks with different data look the same to the outside world, even if the exact algorithm used to do that task to that data is radically different. It's a little like passing around a table of functions, only cleverer.
Edit: a friendly elder reminded me that has requires parens when declaring multiple attributes, just like my and our in Perl 5.
In reply to Re^3: Perl 6, Object Orientation and Melting Brains