in reply to Re: Fun with Typed Objects 1
in thread Fun with Typed Objects 1
I think you hit the nail on the head with your:my $skip = (Dog) Animal->new; or my Dog $skip = Animal->new;
After all. Java has had to use Object with its collections to keep them generic. This leaves it to the programmer to *know* what to cast to when fetching the contents. Imagine this in Perl:my Dog @showdogs;
Eeeew. However, on the flip side perhaps some kind of autotesting at debug run time to see if an object can do what you want would be nice. So when you do the following:foreach my $dog(Dog @showdogs) { print $dog->bark(),"\n"; }
You can specify debug code to run that uses isa() and can() on the references of your choice to test that you are passing the right stuff around.method bark_at ($some_other_dog, $message)
This function returning ok if the var is either an instance of Dog or can do all of Dogs methods. However, in this case its more like an assertation. You could then also create your own $! if you wished.sub method bark_at ($some_other_dog, $message) { if(DEBUG) { die "Not valid class" unless is_obj_instance("Dog", $some_other_ +dog); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Fun with Typed Objects 1 (see isa() considered harmful)
by Aristotle (Chancellor) on Apr 02, 2003 at 23:26 UTC |