Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Perl OOP

by tobyink (Canon)
on Jul 05, 2017 at 09:16 UTC ( [id://1194212]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl OOP
in thread Perl OOP

I don't see why that would be good practice.

Let's create a telephone class:

package Example::Phone { use Moo; has number => (is => 'ro', required => 1); sub call { ... } }

Now let's use it:

use Example::Phone; my $dad = Example::Phone->new(number => '+44 123 456 7890'); say "Dad's number is ", $dad->number; $dad->call();

The object is immutable, in that once it's been instantiated, you can't use its public API to alter the number string.

But that shouldn't stop us from subclassing it:

package Example::Phone::Mobile { use Moo; extends 'Example::Phone'; sub send_sms { ... } }

It doesn't in any way compromise the immutability of the parent class.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1194212]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-23 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found