Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Object oriented Perl and Java: A brief examination of design.

by Bloodnok (Vicar)
on Jan 29, 2014 at 13:26 UTC ( [id://1072507]=note: print w/replies, xml ) Need Help??


in reply to Object oriented Perl and Java: A brief examination of design.

Instance/object variables can be defined outside a constructor if something approaching the flyweight pattern is adopted...
package MyPkg; my @Instances; # Visibility restricted to package by lexical declarati +on sub new { my $self = shift; my $opts = ref $_[0] ? shift : { @_ }; push @Instances, { %$opts }; return bless \(my $me = $#Instances), $self; } sub getScore { my $self = shift; return $Instances[$$self]->{score}; }
As for class methods, all subs declared in a package are, by definition, class methods since the package is the equivalent of a class. The invocation context is determined in the subs/methods themselves e.g.
package SomeClass; sub classMethod { my $self = shift; die("Not an object/instance method") if ref $self; . . } sub objMethod { my $self = shift; die("Not an class method") unless ref $self; . . }
Once again, just my 10 penn'orth FWIW, hope it's of interest/use to you

A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-03-19 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found