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

Re: Re: Often Overlooked OO Programming Guidelines

by Ovid (Cardinal)
on Dec 29, 2003 at 21:45 UTC ( #317562=note: print w/ replies, xml ) Need Help??


in reply to Re: Often Overlooked OO Programming Guidelines
in thread Often Overlooked OO Programming Guidelines

Yes, you're correct. I used a rotten example. Here's a clearer example. A corporate customer is assigned to a company, which has an office which has a manager.

  my $manager = $customer->company->office->manager;

Later on, we realize that this is a bad class heirarchy and the customer should belong to an office and the company is superflous to this, but we've hardcoded a chain of method calls and this makes life difficult. What if we had done this:

sub Customer::manager { my $self = shift; return $self->{delegates}{company}->manager; } sub Company::manager { my $self = shift; return $self->{delegates}{office}->manager; } sub Office::manager { my $self = shift; return $self->{delegates}{manager}; }

Now the fix is easy, when we want to drop the Company class reference in the Customer object.

sub Customer::manager { my $self = shift; # return $self->{delegates}{company}->manager return $self->{delegates}{office}->manager; }

Cheers,
Ovid

New address of my CGI Course.


Comment on Re: Re: Often Overlooked OO Programming Guidelines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2014-11-27 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (184 votes), past polls