develooper Front page | perl.perl6.language | Postings from May 2005

Re: Junctions of classes, roles, etc.

Thread Previous | Thread Next
From:
Thomas Sandlaß
Date:
May 2, 2005 09:49
Subject:
Re: Junctions of classes, roles, etc.
Message ID:
42765A06.10206@orthogon.com
David Storrs wrote:
> Let's move this away from simple types like Str and Int for a moment.

If you consider them simple...


> Tell me what this does:
> 
> 
> class Tree { 
>       method bark() { die "Cannot instantiate a Tree--it is abstract!" }
> }
> class Birch { 
>       method bark() { return "White, papery" }
> }
> class Oak { 
>       method bark() { return "Dark, heavy" }
> }
> class Dog {
>       method bark() { print "Woof, woof!"; return "bow wow" }
> }

Four 'pure' classes so far.


> class AlienBeastie isa Tree isa Dog {}

Here you get an error/warning of a composition time conflict between
&Tree::bark and &Dog::bark. BTW, it's 'is' not 'isa'. My preferred
syntax for multiple inheritance is the junctive notation 'is Tree & Dog'
for subclassing because it nicely allows for superclassing with
'is Tree | Dog'.

> class WhiteAlienBeastie isa Birch isa Dog {}

Same for &Birch::bark and &Dog::bark.

> class HeavyAlienBeastie isa Oak isa Dog {}

Same.


> sub Foo(Tree|Dog $x) { $x.bark() }

This might dispatch correctly for 'pure' Trees, Dogs etc.
but not for your mixed classes above.


Regards,
-- 
TSa (Thomas Sandlaß)




Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About