Emperor [SPUG: E-spug takers?]
Stuart Poulin
stuart_poulin at yahoo.com
Fri Dec 17 19:40:23 CST 1999
--- Colin Meyer <cmeyer at zipcon.net> wrote:
> On Fri, Dec 17, 1999 at 01:37:25PM -0800, Stuart Poulin wrote:
> > print "I'll be there" if $day !~ /^Tue/i;
> >
> > There's got to be some clever way to say $Emperor = new clothes; but I
> can't
> > think of it.
> >
>
> I think that it is more of a "has-a" rather than an "is-a" relationship:
>
> $emp = new Sovereign;
>
> $naught = new Clothes;
> $naught->composed_of(undef);
> $naught->looks_like('invisible');
>
> $emp->dress_in($naught);
>
> print $emp->dressed_in->looks_like();
>
> Where looks_like() and composed_of() are accessor methods for attributes of
> object class Clothes and dress_in()/dressed_in() are set/get methods for an
> attribute of class Sovereign.
>
> It is probably confusing to use two different object attribute accessing
> interfraces in the same segment of code, but you can do that in Perl. In
> fact
> you have to use arbitrarily different object interfaces when combining the
> usage of several random modules from CPAN in one program...
>
> -C.
>
>
Well I knew it had to be some kind of aggregation or composition, but it just
didn't seem poetic enough.
But you've given me an idea - Perl doesn't care what you call your
constructors:
package Sovereign;
sub Ruler {
my $class = shift;
bless {}, $class;
}
sub new {
my $self=shift;
}
sub clothes {
my $self=shift;
return "";
}
package main;
my $emperor = Ruler Sovereign;
print $emperor->new->clothes;
__END__
Ooops - did I give away the story?
__________________________________________________
Do You Yahoo!?
Thousands of Stores. Millions of Products. All in one place.
Yahoo! Shopping: http://shopping.yahoo.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list