Here the use and purpose of is_built() method is obscured by two factors. On the one hand, it seems that is_built() has something to do with the instance of a Gadget class (the $g1 object). Am I checking here whether object $g1 was built with name $athing_name? Or, do I simply check that an instance of class Gadget named $athing_name exists and that also it is somehow related to the $g1 object? On the other hand, there's this 'Gadget ... has already been built!' comment that gets printed on the success of the is_built() which sort of points me in the direction of thinking that the latter assertion is true (gadget named so-and-so exists).package Gadget; # # 'build' new gadget... # return undef on fail. # sub new { my ($proto, $name, %args) = @_; my $self = bless {}, $proto; $self->{name} = $name; . . . work with %args . . . return $self; } # # check if a gadget has already been built. # sub is_built { my ($self, $name) = @_; return exists %_built_gadgets{$name}; } 1; package main; my $g1 = new Gadget('knob'); . . . create a bunch of other gadgets . . . if ($g1->is_built($athing_name)) { print "Gadget '$athing_name' has already been built!!\n"; } else { . . . do something useful here . . . }
should be instead written asif ($g1->is_built($athing_name)) {
And also the is_built() sub has to be modified to this:if (Gadget->is_built($athing_name)) {
since as far as the purpose and design of the imagined class goes, this method has no buisiness inside an object. When is used as a per-object method, it implies a weak (or confusing) logical statement. Frankly, I find it hard to frame original line in a clear statement of logic.sub is_built { my ($class, $name) = @_; # return if dealing with a reference... # note: not tested ;) return if (ref $class eq '__PACKAGE__'); . . . # do stuff if this sub is called ast a class # method. ... }
| "There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: poor Perl OO design hinders maintenance effectiveness..
by Fletch (Bishop) on Apr 29, 2002 at 17:29 UTC | |
|
Re: poor Perl OO design hinders maintenance effectiveness..
by pdcawley (Hermit) on Apr 29, 2002 at 21:05 UTC | |
|
Re: poor Perl OO design hinders maintenance effectiveness..
by sfink (Deacon) on Apr 29, 2002 at 23:36 UTC | |
by hakkr (Chaplain) on Apr 30, 2002 at 11:14 UTC | |
by pdcawley (Hermit) on May 01, 2002 at 08:17 UTC |