SPUG: Class::Multimethod Question
Asim Jalis
ajalis at cobaltgroup.com
Fri Jul 7 00:35:13 CDT 2000
On Thu, Jul 06, 2000 at 12:15:28PM -0700, Andy Jacobs wrote:
> You seem to be declaring both "new" functions with the same parameters
> (i.e., '$'). From memory of the talk last night, I think the syntax should
> be more like:
> multimethod new => (ObjectA) => sub [...]
Except this is a constructor. So you have to call it before you have
an instance of the object to call it with.
> But in this case, as your examples show, there is enough information when
> calling your constructor to distinguish between ObjectA and ObjectB without
> using multimethods. The multimethod technique would make more sense if you
> were passing additional parameters to the constructor, and wanted to choose
> ObjectA or ObjectB based on the types of those parameters.
The multimethods technique can potentially be quite useful with
constructors. It is common to provide one constructor which takes
no parameters and then provide other constructors which over-ride the
defaults.
Asim
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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/
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For full traffic, use spug-list for LIST ; otherwise use spug-list-digest
More information about the spug-list
mailing list