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

Re: Often Overlooked OO Programming Guidelines

by Anonymous Monk
on Dec 29, 2003 at 20:56 UTC ( #317547=note: print w/replies, xml ) Need Help??

in reply to Often Overlooked OO Programming Guidelines

Now, imagine that you have that in 20 places in your code, but in the manager class, someone changes name to full_name.

That is a problem with changing a "published" (as opposed to merely public) interface. Your solution is really no solution at all, it just moves the problem: now we have twenty calls to $office->manager_name, and someone changes the office class and renames that method. If something returns an object, you need to feel free to call that object's methods ... otherwise, what is the point of returning the object in the first place?

Replies are listed 'Best First'.
Re: Re: Often Overlooked OO Programming Guidelines
by Ovid (Cardinal) on Dec 29, 2003 at 21:45 UTC

    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; }


    New address of my CGI Course.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://317547]
[Discipulus]: choroba if let your company to hire Tanktalus and marioroy ... what a big fishing!
[Discipulus]: i choice prague!!
[choroba]: 1200 years is enough :-)
[marioroy]: Lady_Aleena my $ans = qx! find . -name "*.pl" -exec ls -l {} \\; !;
[Tanktalus]: My basic problem right now is that if I were willing to move, I could be back in Toronto with a pay raise. We have a number of reasons for not wanting to do that.
[marioroy]: I had to backslash the backslash inside qx.
[Tanktalus]: marioroy++ # nice catch
[Lady_Aleena]: marioroy, that makes kinda makes sense.
[Discipulus]: yes i can survive also in younger town.. but when i passed i saw many strange letters..
[Lady_Aleena]: marioroy, sorry, I am not making sense right now.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-04-23 20:12 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.