Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Often Overlooked OO Programming Guidelines

by Ovid (Cardinal)
on Dec 29, 2003 at 19:42 UTC ( [id://317520]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        sub new {
            my ($class,%data) = @_;
            return bless \%data, $class;
        }
    
  2. or download this
        use Acme::Playmate;
    
    ...
        print "Details for playmate " . $playmate->{ "Name" } . "\n";
        print "Birthdate" . $playmate->{ "BirthDate" } . "\n";
        print "Birthplace" . $playmate->{ "BirthPlace" } . "\n";
    
  3. or download this
        package Some::User;
    
    ...
        sub user { die "user() must be implemented in subclass" }
        sub pass { die "pass() must be implemented in subclass" }
        sub url  { die "url() must be implemented in subclass" }
    
  4. or download this
        package Some::User::Foo;
        sub user { 'bob' }
        sub pass { 'seKret' }
        sub url  { '<a href="http://somesite.com/">http://somesite.com/</a
    +>' }
    
  5. or download this
        my $foo = Some::User->new('Foo');
    
  6. or download this
        print $office->manager->name;
    
  7. or download this
        print $office->manager_name; # manager_name calls $manager->name
    
  8. or download this
        foreach my $tender (@tenders) {
            $tender->apply($order);
        }
    
  9. or download this
        $object->{foo};
    
  10. or download this
        $object->foo;
        $object->set_foo($foo);
    
  11. or download this
        if ($object->error) { 
            $object->log_errors 
        } # bad!
    
  12. or download this
        sub log_errors {
            my $self = shift;
            return $self unless $self->error;
            $self->_log_errors;
        }
    
  13. or download this
        sub connect {
            my $self = shift;
            unless ($self->_get_rss_feed) {
    ...
            }
            $self;
        }
    
  14. or download this
        $object->set_foo( $object->get_foo );
    
  15. or download this
        --- #YAML:1.0 !perl/Product
        bin: 19
    ...
        id: 7
        inv: 22
        modified: 0
    
  16. or download this
        Product 7
        Name:      Shirt
    ...
        On-hand:   22
        Bin:       Aisle 3, Shelf 5b (19)
        Record not modified
    
  17. or download this
        sub new {
            my ($class, %data) = @_;
            bless \%data => $class;
        }
    
  18. or download this
        sub set_some_property {
            my ($self, $property) = @_;
            $self->{some_prorety} = $property; # (sic)
    ...
        }
    
        sub some_property { $_[0]->{some_property} }
    
  19. or download this
        ok($object->set_some_property($foo), 'Setting a property should su
    +cceed');
        is($object->some_property, $foo,     "... and fetching it should a
    +lso succeed");
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://317520]
Approved by coreolyn
Front-paged by jeffa
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-19 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found